@@ -98,7 +98,7 @@ function Exec-Process([string]$command, [string]$commandArgs) {
9898 }
9999}
100100
101- function InitializeDotNetCli ([bool ]$install ) {
101+ function InitializeDotNetCli ([bool ]$install , [ bool ] $createSdkLocationFile ) {
102102 if (Test-Path variable:global:_DotNetInstallDir) {
103103 return $global :_DotNetInstallDir
104104 }
@@ -146,6 +146,22 @@ function InitializeDotNetCli([bool]$install) {
146146 }
147147
148148 $env: DOTNET_INSTALL_DIR = $dotnetRoot
149+
150+ if ($createSdkLocationFile ) {
151+ # Create a temporary file under the toolset dir and rename it to sdk.txt to avoid races.
152+ do {
153+ $sdkCacheFileTemp = Join-Path $ToolsetDir $ ([System.IO.Path ]::GetRandomFileName())
154+ }
155+ until (! (Test-Path $sdkCacheFileTemp ))
156+ Set-Content - Path $sdkCacheFileTemp - Value $dotnetRoot
157+
158+ try {
159+ Rename-Item - Force - Path $sdkCacheFileTemp ' sdk.txt'
160+ } catch {
161+ # Somebody beat us
162+ Remove-Item - Path $sdkCacheFileTemp
163+ }
164+ }
149165 }
150166
151167 # Add dotnet to PATH. This prevents any bare invocation of dotnet in custom
@@ -216,7 +232,10 @@ function InstallDotNet([string] $dotnetRoot,
216232 }
217233 catch {
218234 Write-PipelineTelemetryError - Category ' InitializeToolset' - Message " Failed to install dotnet runtime '$runtime ' from custom location '$runtimeSourceFeed '."
235+ ExitWithExitCode 1
219236 }
237+ } else {
238+ ExitWithExitCode 1
220239 }
221240 }
222241}
@@ -274,8 +293,11 @@ function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements =
274293 $vsMajorVersion = $vsMinVersion.Major
275294 $xcopyMSBuildVersion = " $vsMajorVersion .$ ( $vsMinVersion.Minor ) .0-alpha"
276295 }
277-
278- $vsInstallDir = InitializeXCopyMSBuild $xcopyMSBuildVersion $install
296+
297+ $vsInstallDir = $null
298+ if ($xcopyMSBuildVersion.Trim () -ine " none" ) {
299+ $vsInstallDir = InitializeXCopyMSBuild $xcopyMSBuildVersion $install
300+ }
279301 if ($vsInstallDir -eq $null ) {
280302 throw ' Unable to find Visual Studio that has required version and components installed'
281303 }
0 commit comments