@@ -287,6 +287,25 @@ function InstallDotNet([string] $dotnetRoot,
287287 [string ] $runtimeSourceFeedKey = ' ' ,
288288 [switch ] $noPath ) {
289289
290+ $dotnetVersionLabel = " 'sdk v$version '"
291+
292+ if ($runtime -ne ' ' -and $runtime -ne ' sdk' ) {
293+ $runtimePath = $dotnetRoot
294+ $runtimePath = $runtimePath + " \shared"
295+ if ($runtime -eq " dotnet" ) { $runtimePath = $runtimePath + " \Microsoft.NETCore.App" }
296+ if ($runtime -eq " aspnetcore" ) { $runtimePath = $runtimePath + " \Microsoft.AspNetCore.App" }
297+ if ($runtime -eq " windowsdesktop" ) { $runtimePath = $runtimePath + " \Microsoft.WindowsDesktop.App" }
298+ $runtimePath = $runtimePath + " \" + $version
299+
300+ $dotnetVersionLabel = " runtime toolset '$runtime /$architecture v$version '"
301+
302+ if (Test-Path $runtimePath ) {
303+ Write-Host " Runtime toolset '$runtime /$architecture v$version ' already installed."
304+ $installSuccess = $true
305+ Exit
306+ }
307+ }
308+
290309 $installScript = GetDotNetInstallScript $dotnetRoot
291310 $installParameters = @ {
292311 Version = $version
@@ -323,18 +342,18 @@ function InstallDotNet([string] $dotnetRoot,
323342 } else {
324343 $location = " public location" ;
325344 }
326- Write-Host " Attempting to install dotnet from $location ."
345+ Write-Host " Attempting to install $dotnetVersionLabel from $location ."
327346 try {
328347 & $installScript @variation
329348 $installSuccess = $true
330349 break
331350 }
332351 catch {
333- Write-Host " Failed to install dotnet from $location ."
352+ Write-Host " Failed to install $dotnetVersionLabel from $location ."
334353 }
335354 }
336355 if (-not $installSuccess ) {
337- Write-PipelineTelemetryError - Category ' InitializeToolset' - Message " Failed to install dotnet from any of the specified locations."
356+ Write-PipelineTelemetryError - Category ' InitializeToolset' - Message " Failed to install $dotnetVersionLabel from any of the specified locations."
338357 ExitWithExitCode 1
339358 }
340359}
@@ -399,7 +418,8 @@ function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements =
399418 # Locate Visual Studio installation or download x-copy msbuild.
400419 $vsInfo = LocateVisualStudio $vsRequirements
401420 if ($vsInfo -ne $null ) {
402- $vsInstallDir = $vsInfo.installationPath
421+ # Ensure vsInstallDir has a trailing slash
422+ $vsInstallDir = Join-Path $vsInfo.installationPath " \"
403423 $vsMajorVersion = $vsInfo.installationVersion.Split (' .' )[0 ]
404424
405425 InitializeVisualStudioEnvironmentVariables $vsInstallDir $vsMajorVersion
0 commit comments