@@ -96,6 +96,9 @@ function Exec-Process([string]$command, [string]$commandArgs) {
9696 }
9797}
9898
99+ # createSdkLocationFile parameter enables a file being generated under the toolset directory
100+ # which writes the sdk's location into. This is only necessary for cmd --> powershell invocations
101+ # as dot sourcing isn't possible.
99102function InitializeDotNetCli ([bool ]$install , [bool ]$createSdkLocationFile ) {
100103 if (Test-Path variable:global:_DotNetInstallDir) {
101104 return $global :_DotNetInstallDir
@@ -144,21 +147,23 @@ function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) {
144147 }
145148
146149 $env: DOTNET_INSTALL_DIR = $dotnetRoot
150+ }
147151
148- if ($createSdkLocationFile ) {
149- # Create a temporary file under the toolset dir and rename it to sdk.txt to avoid races.
150- do {
151- $sdkCacheFileTemp = Join-Path $ToolsetDir $ ([System.IO.Path ]::GetRandomFileName())
152- }
153- until (! (Test-Path $sdkCacheFileTemp ))
154- Set-Content - Path $sdkCacheFileTemp - Value $dotnetRoot
155-
156- try {
157- Rename-Item - Force - Path $sdkCacheFileTemp ' sdk.txt'
158- } catch {
159- # Somebody beat us
160- Remove-Item - Path $sdkCacheFileTemp
161- }
152+ # Creates a temporary file under the toolset dir.
153+ # The following code block is protecting against concurrent access so that this function can
154+ # be called in parallel.
155+ if ($createSdkLocationFile ) {
156+ do {
157+ $sdkCacheFileTemp = Join-Path $ToolsetDir $ ([System.IO.Path ]::GetRandomFileName())
158+ }
159+ until (! (Test-Path $sdkCacheFileTemp ))
160+ Set-Content - Path $sdkCacheFileTemp - Value $dotnetRoot
161+
162+ try {
163+ Rename-Item - Force - Path $sdkCacheFileTemp ' sdk.txt'
164+ } catch {
165+ # Somebody beat us
166+ Remove-Item - Path $sdkCacheFileTemp
162167 }
163168 }
164169
0 commit comments