From e83e6f73f968b325373dca08a12c1a8373a371d1 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 17 Nov 2022 07:24:56 +0100 Subject: Provisioning: MSVC 2019 update: Add Vswhere helper function Change-Id: Idd6bf24450d9447c38c39c64abff5b55d71c12b9 Reviewed-by: Miguel Costa (cherry picked from commit 37c0cf82aeffd08678f702d49377652605778679) --- .../common/windows/update-msvc2019.ps1 | 54 +++++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/coin/provisioning/common/windows/update-msvc2019.ps1 b/coin/provisioning/common/windows/update-msvc2019.ps1 index 7a482f01..3ab94582 100644 --- a/coin/provisioning/common/windows/update-msvc2019.ps1 +++ b/coin/provisioning/common/windows/update-msvc2019.ps1 @@ -73,15 +73,57 @@ function Install { Remove-Item -Force -Path $installerPath } +function Get-Vswhere-Property { + Param ( + [ValidateSet(2017, 2019, 2022)] + [int] $vsYear = $(BadParam("Visual Studio Year")), + + [ValidatePattern("Professional|Build *Tools|Community|Enterprise")] + [string] $vsEdition = $(BadParam("Visual Studio Edition")), + + [string] $property = $(BadParam("vswhere property")) + ) + + $range = switch ($vsYear) + { + 2017 { "[15.0,16`)" } + 2019 { "[16.0,17`)" } + 2022 { "[17.0,18`)" } + } + + $vsEdition = $vsEdition -replace " ","" + + $vswhereInfo = New-Object System.Diagnostics.ProcessStartInfo + $vswhereInfo.FileName = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + $vswhereInfo.RedirectStandardError = $true + $vswhereInfo.RedirectStandardOutput = $true + $vswhereInfo.UseShellExecute = $false + $vswhereInfo.Arguments = "-version $range", "-latest", ` + "-products Microsoft.VisualStudio.Product.$vsEdition", "-property $property" + $vswhereProcess = New-Object System.Diagnostics.Process + $vswhereProcess.StartInfo = $vswhereInfo + $vswhereProcess.Start() | Out-Null + $vswhereProcess.WaitForExit() + $stdout = $vswhereProcess.StandardOutput.ReadToEnd() + if ([string]::IsNullOrEmpty($stdout)) + { + throw "VS edition or property $property not found by vswhere" + } + $stderr = $vswhereProcess.StandardError.ReadToEnd() + $vsExit = $vswhereProcess.ExitCode + if ($vsExit -ne 0) + { + throw "vswhere failed with exit code $vsExit. stderr: $stderr" + } + return $stdout +} + Install $urlOfficial_vsInstaller $urlCache_vsInstaller $sha1_vsInstaller # Install $urlOfficial_buildToolsInstaller $urlCache_buildToolsInstaller $sha1_buildToolsInstaller -$msvc2019Version = (cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" ` - -version [16.0,17.0`) -latest -property catalog_productDisplayVersion 2`>`&1) -$msvc2019Complete = (cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" ` - -version [16.0,17.0`) -latest -property isComplete 2`>`&1) -$msvc2019Launchable = (cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" ` - -version [16.0,17.0`) -latest -property isLaunchable 2`>`&1) +$msvc2019Version = Get-Vswhere-Property 2019 "Professional" catalog_productDisplayVersion +$msvc2019Complete = Get-Vswhere-Property 2019 "Professional" isComplete +$msvc2019Launchable = Get-Vswhere-Property 2019 "Professional" isLaunchable if($msvc2019Version -ne $version -or [int]$msvc2019Complete -ne 1 ` -or [int]$msvc2019Launchable -ne 1) { -- cgit v1.2.1