diff --git a/Directory.Build.rsp b/Directory.Build.rsp new file mode 100644 index 000000000..9a833a034 --- /dev/null +++ b/Directory.Build.rsp @@ -0,0 +1,16 @@ +#------------------------------------------------------------------------------ +# This file contains command-line options that MSBuild will process as part of +# every build, unless the "/noautoresponse" switch is specified. +# +# MSBuild processes the options in this file first, before processing the +# options on the command line. As a result, options on the command line can +# override the options in this file. However, depending on the options being +# set, the overriding can also result in conflicts. +# +# NOTE: The "/noautoresponse" switch cannot be specified in this file, nor in +# any response file that is referenced by this file. +#------------------------------------------------------------------------------ +/nr:false +/m +/verbosity:minimal +/clp:Summary;ForceNoAlign diff --git a/azure-pipelines/Get-TempToolsPath.ps1 b/azure-pipelines/Get-TempToolsPath.ps1 index 97c552c06..bb3da8e33 100644 --- a/azure-pipelines/Get-TempToolsPath.ps1 +++ b/azure-pipelines/Get-TempToolsPath.ps1 @@ -1,7 +1,7 @@ -if ($env:AGENT_TOOLSDIRECTORY) { - $path = "$env:AGENT_TOOLSDIRECTORY\vs-platform\tools" +if ($env:AGENT_TEMPDIRECTORY) { + $path = "$env:AGENT_TEMPDIRECTORY\$env:BUILD_BUILDID" } elseif ($env:localappdata) { - $path = "$env:localappdata\vs-platform\tools" + $path = "$env:localappdata\gitrepos\tools" } else { $path = "$PSScriptRoot\..\obj\tools" } diff --git a/azure-pipelines/Get-nbgv.ps1 b/azure-pipelines/Get-nbgv.ps1 index 925eecddb..a5be2cf7c 100644 --- a/azure-pipelines/Get-nbgv.ps1 +++ b/azure-pipelines/Get-nbgv.ps1 @@ -10,11 +10,7 @@ if ($existingTool) { return $existingTool.Path } -if ($env:AGENT_TEMPDIRECTORY) { - $toolInstallDir = "$env:AGENT_TEMPDIRECTORY/$env:BUILD_BUILDID" -} else { - $toolInstallDir = "$PSScriptRoot/../obj/tools" -} +$toolInstallDir = & "$PSScriptRoot/Get-TempToolsPath.ps1" $toolPath = "$toolInstallDir/nbgv" if (!(Test-Path $toolInstallDir)) { New-Item -Path $toolInstallDir -ItemType Directory | Out-Null } diff --git a/azure-pipelines/install-dependencies.yml b/azure-pipelines/install-dependencies.yml index 5b1ac4afd..7563bc1f8 100644 --- a/azure-pipelines/install-dependencies.yml +++ b/azure-pipelines/install-dependencies.yml @@ -7,8 +7,14 @@ steps: $AccessToken = '$(System.AccessToken)' # Avoid specifying the access token directly on the init.ps1 command line to avoid it showing up in errors .\init.ps1 -AccessToken $AccessToken ${{ parameters['initArgs'] }} -UpgradePrerequisites dotnet --info + + # Print mono version if it is present. + if (Get-Command mono -ErrorAction SilentlyContinue) { + mono --version + } displayName: Install prerequisites - powershell: azure-pipelines/variables/_pipelines.ps1 failOnStderr: true displayName: Set pipeline variables based on source + name: SetPipelineVariables diff --git a/azure-pipelines/release.yml b/azure-pipelines/release.yml index 4f6ebd829..316655a8e 100644 --- a/azure-pipelines/release.yml +++ b/azure-pipelines/release.yml @@ -21,6 +21,7 @@ stages: runOnce: deploy: steps: + - download: none - powershell: | Write-Host "##vso[build.updatebuildnumber]$(resources.pipeline.CI.runName)" displayName: Set pipeline name diff --git a/azure-pipelines/variables/_pipelines.ps1 b/azure-pipelines/variables/_pipelines.ps1 index 14d6ffc28..867b7fc8b 100644 --- a/azure-pipelines/variables/_pipelines.ps1 +++ b/azure-pipelines/variables/_pipelines.ps1 @@ -8,13 +8,16 @@ # Always use ALL CAPS for env var names since Azure Pipelines converts variable names to all caps and on non-Windows OS, env vars are case sensitive. $keyCaps = $_.Key.ToUpper() if (Test-Path -Path "env:$keyCaps") { - Write-Host "Skipping setting $keyCaps because variable is already set." -ForegroundColor Cyan + Write-Host "Skipping setting $keyCaps because variable is already set to '$(Get-Content env:$keyCaps)'." -ForegroundColor Cyan } else { Write-Host "$keyCaps=$($_.Value)" -ForegroundColor Yellow if ($env:TF_BUILD) { - Write-Host "##vso[task.setvariable variable=$keyCaps;]$($_.Value)" + # Create two variables: the first that can be used by its simple name and accessible only within this job. + Write-Host "##vso[task.setvariable variable=$keyCaps]$($_.Value)" + # and the second that works across jobs and stages but must be fully qualified when referenced. + Write-Host "##vso[task.setvariable variable=$keyCaps;isOutput=true]$($_.Value)" } elseif ($env:GITHUB_ACTIONS) { - Write-Host "::set-env name=$keyCaps::$($_.Value)" + Add-Content -Path $env:GITHUB_ENV -Value "$keyCaps=$($_.Value)" } Set-Item -Path "env:$keyCaps" -Value $_.Value } diff --git a/init.cmd b/init.cmd index 970285c2f..667efabb7 100644 --- a/init.cmd +++ b/init.cmd @@ -1,4 +1,20 @@ @echo off SETLOCAL set PS1UnderCmd=1 + +:: Get the datetime in a format that can go in a filename. +set _my_datetime=%date%_%time% +set _my_datetime=%_my_datetime: =_% +set _my_datetime=%_my_datetime::=% +set _my_datetime=%_my_datetime:/=_% +set _my_datetime=%_my_datetime:.=_% +set CmdEnvScriptPath=%temp%\envvarscript_%_my_datetime%.cmd + powershell.exe -NoProfile -NoLogo -ExecutionPolicy bypass -Command "try { & '%~dpn0.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }" + +:: Set environment variables in the parent cmd.exe process. +IF EXIST "%CmdEnvScriptPath%" ( + ENDLOCAL + CALL "%CmdEnvScriptPath%" + DEL "%CmdEnvScriptPath%" +) diff --git a/init.ps1 b/init.ps1 index 72d68b5fa..e5aad5bfa 100755 --- a/init.ps1 +++ b/init.ps1 @@ -2,28 +2,31 @@ <# .SYNOPSIS -Installs dependencies required to build and test the projects in this repository. + Installs dependencies required to build and test the projects in this repository. .DESCRIPTION -This MAY not require elevation, as the SDK and runtimes are installed to a per-user location, -unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location. -See detailed help on that switch for more information. + This MAY not require elevation, as the SDK and runtimes are installed to a per-user location, + unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location. + See detailed help on that switch for more information. + + The CmdEnvScriptPath environment variable may be optionally set to a path to a cmd shell script to be created (or appended to if it already exists) that will set the environment variables in cmd.exe that are set within the PowerShell environment. + This is used by init.cmd in order to reapply any new environment variables to the parent cmd.exe process that were set in the powershell child process. .PARAMETER InstallLocality -A value indicating whether dependencies should be installed locally to the repo or at a per-user location. -Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache. -Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script. -Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build. -When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used. -Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`. -Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it. + A value indicating whether dependencies should be installed locally to the repo or at a per-user location. + Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache. + Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script. + Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build. + When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used. + Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`. + Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it. .PARAMETER NoPrerequisites -Skips the installation of prerequisite software (e.g. SDKs, tools). + Skips the installation of prerequisite software (e.g. SDKs, tools). .PARAMETER UpgradePrerequisites -Takes time to install prerequisites even if they are already present in case they need to be upgraded. -No effect if -NoPrerequisites is specified. + Takes time to install prerequisites even if they are already present in case they need to be upgraded. + No effect if -NoPrerequisites is specified. .PARAMETER NoRestore -Skips the package restore step. + Skips the package restore step. .PARAMETER AccessToken -An optional access token for authenticating to Azure Artifacts authenticated feeds. + An optional access token for authenticating to Azure Artifacts authenticated feeds. #> [CmdletBinding(SupportsShouldProcess=$true)] Param ( @@ -71,7 +74,7 @@ try { } } - & "$PSScriptRoot\azure-pipelines\Set-EnvVars.ps1" -Variables $EnvVars | Out-Null + & "$PSScriptRoot/tools/Set-EnvVars.ps1" -Variables $EnvVars | Out-Null } catch { Write-Error $error[0] diff --git a/tools/Check-DotNetRuntime.ps1 b/tools/Check-DotNetRuntime.ps1 new file mode 100644 index 000000000..9d0121095 --- /dev/null +++ b/tools/Check-DotNetRuntime.ps1 @@ -0,0 +1,41 @@ +<# +.SYNOPSIS + Checks whether a given .NET Core runtime is installed. +#> +[CmdletBinding()] +Param ( + [Parameter()] + [ValidateSet('Microsoft.AspNetCore.App','Microsoft.NETCore.App')] + [string]$Runtime='Microsoft.NETCore.App', + [Parameter(Mandatory=$true)] + [Version]$Version +) + +$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue +if (!$dotnet) { + # Nothing is installed. + Write-Output $false + exit 1 +} + +Function IsVersionMatch { + Param( + [Parameter()] + $actualVersion + ) + return $actualVersion -and + $Version.Major -eq $actualVersion.Major -and + $Version.Minor -eq $actualVersion.Minor -and + (($Version.Build -eq -1) -or ($Version.Build -eq $actualVersion.Build)) -and + (($Version.Revision -eq -1) -or ($Version.Revision -eq $actualVersion.Revision)) +} + +$installedRuntimes = dotnet --list-runtimes |? { $_.Split()[0] -ieq $Runtime } |% { $v = $null; [Version]::tryparse($_.Split()[1], [ref] $v); $v } +$matchingRuntimes = $installedRuntimes |? { IsVersionMatch -actualVersion $_ } +if (!$matchingRuntimes) { + Write-Output $false + exit 1 +} + +Write-Output $true +exit 0 diff --git a/tools/Check-DotNetSdk.ps1 b/tools/Check-DotNetSdk.ps1 new file mode 100644 index 000000000..6c9fa772c --- /dev/null +++ b/tools/Check-DotNetSdk.ps1 @@ -0,0 +1,37 @@ +<# +.SYNOPSIS + Checks whether the .NET Core SDK required by this repo is installed. +#> +[CmdletBinding()] +Param ( +) + +$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue +if (!$dotnet) { + # Nothing is installed. + Write-Output $false + exit 1 +} + +# We need to set the current directory so dotnet considers the SDK required by our global.json file. +Push-Location "$PSScriptRoot\.." +try { + dotnet -h 2>&1 | Out-Null + if (($LASTEXITCODE -eq 129) -or # On Linux + ($LASTEXITCODE -eq -2147450751) # On Windows + ) { + # These exit codes indicate no matching SDK exists. + Write-Output $false + exit 2 + } + + # The required SDK is already installed! + Write-Output $true + exit 0 +} catch { + # I don't know why, but on some build agents (e.g. MicroBuild), an exception is thrown from the `dotnet` invocation when a match is not found. + Write-Output $false + exit 3 +} finally { + Pop-Location +} diff --git a/tools/Install-DotNetSdk.ps1 b/tools/Install-DotNetSdk.ps1 index 05cfef02a..a8407a32e 100755 --- a/tools/Install-DotNetSdk.ps1 +++ b/tools/Install-DotNetSdk.ps1 @@ -2,19 +2,19 @@ <# .SYNOPSIS -Installs the .NET SDK specified in the global.json file at the root of this repository, -along with supporting .NET Core runtimes used for testing. + Installs the .NET SDK specified in the global.json file at the root of this repository, + along with supporting .NET Core runtimes used for testing. .DESCRIPTION -This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location, -unless `-InstallLocality machine` is specified. + This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location, + unless `-InstallLocality machine` is specified. .PARAMETER InstallLocality -A value indicating whether dependencies should be installed locally to the repo or at a per-user location. -Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache. -Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script. -Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build. -When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used. -Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`. -Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it. + A value indicating whether dependencies should be installed locally to the repo or at a per-user location. + Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache. + Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script. + Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build. + When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used. + Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`. + Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it. #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')] Param ( @@ -31,17 +31,25 @@ $sdkVersion = & "$PSScriptRoot/../azure-pipelines/variables/DotNetSdkVersion.ps1 # Search for all .NET Core runtime versions referenced from MSBuild projects and arrange to install them. $runtimeVersions = @() +$windowsDesktopRuntimeVersions = @() Get-ChildItem "$PSScriptRoot\..\src\*.*proj","$PSScriptRoot\..\tests\*.*proj","$PSScriptRoot\..\Directory.Build.props" -Recurse |% { $projXml = [xml](Get-Content -Path $_) - $targetFrameworks = $projXml.Project.PropertyGroup.TargetFramework - if (!$targetFrameworks) { - $targetFrameworks = $projXml.Project.PropertyGroup.TargetFrameworks - if ($targetFrameworks) { - $targetFrameworks = $targetFrameworks -Split ';' + $pg = $projXml.Project.PropertyGroup + if ($pg) { + $targetFrameworks = $pg.TargetFramework + if (!$targetFrameworks) { + $targetFrameworks = $pg.TargetFrameworks + if ($targetFrameworks) { + $targetFrameworks = $targetFrameworks -Split ';' + } } } $targetFrameworks |? { $_ -match 'netcoreapp(\d+\.\d+)' } |% { - $runtimeVersions += $Matches[1] + $v = $Matches[1] + $runtimeVersions += $v + if ($v -ge '3.0' -and -not ($IsMacOS -or $IsLinux)) { + $windowsDesktopRuntimeVersions += $v + } } } @@ -128,16 +136,16 @@ if ($InstallLocality -eq 'machine') { Write-Host "Installing .NET Core SDK and runtimes to $DotNetInstallDir" -ForegroundColor Blue if ($DotNetInstallDir) { - $switches += '-InstallDir',$DotNetInstallDir + $switches += '-InstallDir',"`"$DotNetInstallDir`"" $envVars['DOTNET_MULTILEVEL_LOOKUP'] = '0' $envVars['DOTNET_ROOT'] = $DotNetInstallDir } if ($IsMacOS -or $IsLinux) { - $DownloadUri = "https://dot.net/v1/dotnet-install.sh" + $DownloadUri = "https://raw.githubusercontent.com/dotnet/install-scripts/49d5da7f7d313aa65d24fe95cc29767faef553fd/src/dotnet-install.sh" $DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.sh" } else { - $DownloadUri = "https://dot.net/v1/dotnet-install.ps1" + $DownloadUri = "https://raw.githubusercontent.com/dotnet/install-scripts/49d5da7f7d313aa65d24fe95cc29767faef553fd/src/dotnet-install.ps1" $DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.ps1" } @@ -148,22 +156,62 @@ if (-not (Test-Path $DotNetInstallScriptPath)) { } } +# In case the script we invoke is in a directory with spaces, wrap it with single quotes. +# In case the path includes single quotes, escape them. +$DotNetInstallScriptPathExpression = $DotNetInstallScriptPath.Replace("'", "''") +$DotNetInstallScriptPathExpression = "& '$DotNetInstallScriptPathExpression'" + +$anythingInstalled = $false +$global:LASTEXITCODE = 0 + if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) { - Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches" + $anythingInstalled = $true + Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion $switches" + + if ($LASTEXITCODE -ne 0) { + Write-Error ".NET SDK installation failure: $LASTEXITCODE" + exit $LASTEXITCODE + } } else { - Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches -DryRun" + Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion $switches -DryRun" } -$switches += '-Runtime','dotnet' +$dotnetRuntimeSwitches = $switches + '-Runtime','dotnet' -$runtimeVersions | Get-Unique |% { +$runtimeVersions | Sort-Object -Unique |% { if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) { - Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches" + $anythingInstalled = $true + Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ $dotnetRuntimeSwitches" + + if ($LASTEXITCODE -ne 0) { + Write-Error ".NET SDK installation failure: $LASTEXITCODE" + exit $LASTEXITCODE + } } else { - Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches -DryRun" + Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ $dotnetRuntimeSwitches -DryRun" + } +} + +$windowsDesktopRuntimeSwitches = $switches + '-Runtime','windowsdesktop' + +$windowsDesktopRuntimeVersions | Sort-Object -Unique |% { + if ($PSCmdlet.ShouldProcess(".NET Core WindowsDesktop runtime $_", "Install")) { + $anythingInstalled = $true + Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ $windowsDesktopRuntimeSwitches" + + if ($LASTEXITCODE -ne 0) { + Write-Error ".NET SDK installation failure: $LASTEXITCODE" + exit $LASTEXITCODE + } + } else { + Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ $windowsDesktopRuntimeSwitches -DryRun" } } if ($PSCmdlet.ShouldProcess("Set DOTNET environment variables to discover these installed runtimes?")) { - & "$PSScriptRoot/../azure-pipelines/Set-EnvVars.ps1" -Variables $envVars -PrependPath $DotNetInstallDir | Out-Null + & "$PSScriptRoot/Set-EnvVars.ps1" -Variables $envVars -PrependPath $DotNetInstallDir | Out-Null +} + +if ($anythingInstalled -and ($InstallLocality -ne 'machine') -and !$env:TF_BUILD -and !$env:GITHUB_ACTIONS) { + Write-Warning ".NET Core runtimes or SDKs were installed to a non-machine location. Perform your builds or open Visual Studio from this same environment in order for tools to discover the location of these dependencies." } diff --git a/tools/Install-NuGetCredProvider.ps1 b/tools/Install-NuGetCredProvider.ps1 index 2b3fb6fb4..6d3100349 100644 --- a/tools/Install-NuGetCredProvider.ps1 +++ b/tools/Install-NuGetCredProvider.ps1 @@ -19,6 +19,8 @@ Param ( [string]$AccessToken ) +$envVars = @{} + $toolsPath = & "$PSScriptRoot\..\azure-pipelines\Get-TempToolsPath.ps1" if ($IsMacOS -or $IsLinux) { @@ -66,9 +68,9 @@ if ($AccessToken) { Add-Member -InputObject $auth -MemberType NoteProperty -Name endpointCredentials -Value $endpoints $authJson = ConvertTo-Json -InputObject $auth - $envVars = @{ + $envVars += @{ 'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS'=$authJson; } - - & "$PSScriptRoot\..\azure-pipelines\Set-EnvVars.ps1" -Variables $envVars | Out-Null } + +& "$PSScriptRoot/Set-EnvVars.ps1" -Variables $envVars | Out-Null diff --git a/azure-pipelines/Set-EnvVars.ps1 b/tools/Set-EnvVars.ps1 similarity index 67% rename from azure-pipelines/Set-EnvVars.ps1 rename to tools/Set-EnvVars.ps1 index 9d14d9aa0..3f6f86ba5 100644 --- a/azure-pipelines/Set-EnvVars.ps1 +++ b/tools/Set-EnvVars.ps1 @@ -4,8 +4,13 @@ Azure Pipeline and CMD environments are considered. .PARAMETER Variables A hashtable of variables to be set. +.PARAMETER PrependPath + A set of paths to prepend to the PATH environment variable. .OUTPUTS A boolean indicating whether the environment variables can be expected to propagate to the caller's environment. +.DESCRIPTION + The CmdEnvScriptPath environment variable may be optionally set to a path to a cmd shell script to be created (or appended to if it already exists) that will set the environment variables in cmd.exe that are set within the PowerShell environment. + This is used by init.cmd in order to reapply any new environment variables to the parent cmd.exe process that were set in the powershell child process. #> [CmdletBinding(SupportsShouldProcess=$true)] Param( @@ -18,7 +23,7 @@ if ($Variables.Count -eq 0) { return $true } -$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and $env:PS1UnderCmd -eq '1' +$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and !$env:CmdEnvScriptPath -and ($env:PS1UnderCmd -eq '1') if ($cmdInstructions) { Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe" Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue @@ -38,6 +43,7 @@ if ($env:GITHUB_ACTIONS) { Write-Host "GitHub Actions detected. Logging commands will be used to propagate environment variables and prepend path." } +$CmdEnvScript = '' $Variables.GetEnumerator() |% { Set-Item -Path env:$($_.Key) -Value $_.Value @@ -46,12 +52,14 @@ $Variables.GetEnumerator() |% { Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)" } if ($env:GITHUB_ACTIONS) { - Write-Host "::set-env name=$($_.Key)::$($_.Value)" + Add-Content -Path $env:GITHUB_ENV -Value "$($_.Key)=$($_.Value)" } if ($cmdInstructions) { Write-Host "SET $($_.Key)=$($_.Value)" } + + $CmdEnvScript += "SET $($_.Key)=$($_.Value)`r`n" } $pathDelimiter = ';' @@ -71,9 +79,19 @@ if ($PrependPath) { Write-Host "##vso[task.prependpath]$_" } if ($env:GITHUB_ACTIONS) { - Write-Host "::add-path::$_" + Add-Content -Path $env:GITHUB_PATH -Value $_ } + + $CmdEnvScript += "SET PATH=$_$pathDelimiter%PATH%" + } +} + +if ($env:CmdEnvScriptPath) { + if (Test-Path $env:CmdEnvScriptPath) { + $CmdEnvScript = (Get-Content -Path $env:CmdEnvScriptPath) + $CmdEnvScript } + + Set-Content -Path $env:CmdEnvScriptPath -Value $CmdEnvScript } return !$cmdInstructions