From fdca90b7f67bc2b0d0b37beac6e8e72427642cf1 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 10 Apr 2019 14:55:58 -0700 Subject: [PATCH] Ensure InstallVisualStudio.ps1 doesn't mix RTM and preview versions if both are installed (#9260) --- eng/scripts/InstallVisualStudio.ps1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/eng/scripts/InstallVisualStudio.ps1 b/eng/scripts/InstallVisualStudio.ps1 index 0cd6589738..28a04d952c 100644 --- a/eng/scripts/InstallVisualStudio.ps1 +++ b/eng/scripts/InstallVisualStudio.ps1 @@ -50,12 +50,26 @@ $bootstrapper = "$intermedateDir\vsinstaller.exe" $ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138 Invoke-WebRequest -Uri "https://aka.ms/vs/16/release/vs_$($Edition.ToLowerInvariant()).exe" -OutFile $bootstrapper +$responseFile = "$PSScriptRoot\vs.json" +if ("$Edition" -eq "BuildTools") { + $responseFile = "$PSScriptRoot\vs.buildtools.json" +} + +$channelId = (Get-Content $responseFile | ConvertFrom-Json).channelId + $productId = "Microsoft.VisualStudio.Product.$Edition" if (-not $InstallPath) { $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" if (Test-Path $vsWhere) { - $InstallPath = &$vsWhere -version '[16,17)' -latest -prerelease -products $productId -property installationPath + $installations = & $vsWhere -version '[16,17)' -format json -sort -prerelease -products $productId | ConvertFrom-Json + foreach ($installation in $installations) { + Write-Host "Found '$($installation.installationName)' in '$($installation.installationPath)', channel = '$($installation.channelId)'" + if ($installation.channelId -eq $channelId) { + $InstallPath = $installation.installationPath + break + } + } } } @@ -71,11 +85,6 @@ if (Test-path $InstallPath) { $arguments += 'modify' } -$responseFile = "$PSScriptRoot\vs.json" -if ("$Edition" -eq "BuildTools") { - $responseFile = "$PSScriptRoot\vs.buildtools.json" -} - $arguments += ` '--productId', $productId, ` '--installPath', "`"$InstallPath`"", `