@@ -264,9 +264,10 @@ function SetDeploymentOutputs(
264264) {
265265 $deploymentEnvironmentVariables = $environmentVariables.Clone ()
266266 $deploymentOutputs = BuildDeploymentOutputs $serviceName $azContext $deployment $deploymentEnvironmentVariables
267+ $isBicep = $templateFile.originalFilePath -and $templateFile.originalFilePath.EndsWith (" .bicep" )
267268
268- if ( $OutFile ) {
269- if ($IsWindows -and $Language -eq ' dotnet' ) {
269+ # Azure SDK for .NET on Windows uses DPAPI-encrypted, JSON-encoded environment variables.
270+ if ($OutFile -and $IsWindows -and $Language -eq ' dotnet' ) {
270271 $outputFile = " $ ( $templateFile.originalFilePath ) .env"
271272
272273 $environmentText = $deploymentOutputs | ConvertTo-Json ;
@@ -276,29 +277,29 @@ function SetDeploymentOutputs(
276277 Set-Content $outputFile - Value $protectedBytes - AsByteStream - Force
277278
278279 Write-Host " Test environment settings`n $environmentText `n stored into encrypted $outputFile "
280+ }
281+ # Any Bicep template in a repo that has opted into .env files.
282+ elseif ($OutFile -and $isBicep ) {
283+ $bicepTemplateFile = $templateFile.originalFilePath
284+
285+ # Make sure the file would not write secrets to .env file.
286+ if (! (LintBicepFile $bicepTemplateFile )) {
287+ Write-Error " $bicepTemplateFile may write secrets. No file written."
279288 }
280- elseif ($templateFile.originalFilePath -and $templateFile.originalFilePath.EndsWith (" .bicep" )) {
281- $bicepTemplateFile = $templateFile.originalFilePath
289+ $outputFile = $bicepTemplateFile | Split-Path | Join-Path - ChildPath ' .env'
282290
283- # Make sure the file would not write secrets to .env file.
284- if (! (LintBicepFile $bicepTemplateFile )) {
285- Write-Error " $bicepTemplateFile may write secrets. No file written."
291+ # Make sure the file would be ignored.
292+ git check- ignore -- " $outputFile " > $null
293+ if ($? ) {
294+ $environmentText = foreach ($kv in $deploymentOutputs.GetEnumerator ()) {
295+ " $ ( $kv.Key ) =`" $ ( $kv.Value ) `" "
286296 }
287- $outputFile = $bicepTemplateFile | Split-Path | Join-Path - ChildPath ' .env'
288297
289- # Make sure the file would be ignored.
290- git check- ignore -- " $outputFile " > $null
291- if ($? ) {
292- $environmentText = foreach ($kv in $deploymentOutputs.GetEnumerator ()) {
293- " $ ( $kv.Key ) =`" $ ( $kv.Value ) `" "
294- }
295-
296- Set-Content $outputFile - Value $environmentText - Force
297- Write-Host " Test environment settings`n $environmentText `n stored in $outputFile "
298- }
299- else {
300- Write-Error " $outputFile is not ignored by .gitignore. No file written."
301- }
298+ Set-Content $outputFile - Value $environmentText - Force
299+ Write-Host " Test environment settings`n $environmentText `n stored in $outputFile "
300+ }
301+ else {
302+ Write-Error " $outputFile is not ignored by .gitignore. No file written."
302303 }
303304 }
304305 else {
0 commit comments