From ebfb49f956e81732c9b701991dd75bded28cb4fa Mon Sep 17 00:00:00 2001 From: Nikhil Dabas Date: Sun, 18 Jul 2021 02:59:57 +0530 Subject: [PATCH] Fixes for older VS2019 versions --- common.ps1 | 15 +++++++++------ pico-env.cmd | 2 +- tests/setup-oldvs.ps1 | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common.ps1 b/common.ps1 index 2639f10..da312fe 100644 --- a/common.ps1 +++ b/common.ps1 @@ -31,12 +31,15 @@ function exec { $ErrorActionPreference = 'Continue' $global:LASTEXITCODE = 0 - # Convert stderr in ErrorRecord objects back to strings - & $private:cmd 2>&1 | ForEach-Object { "$_" } + try { + # Convert stderr in ErrorRecord objects back to strings + & $cmd 2>&1 | ForEach-Object { "$_" } - $ErrorActionPreference = $private:eap - - if ($global:LASTEXITCODE -ne 0) { - Write-Error "Command '$private:cmd' exited with code $LASTEXITCODE" + if ($LASTEXITCODE -ne 0) { + throw "Command '$cmd' exited with code $LASTEXITCODE" + } + } + finally { + $ErrorActionPreference = $eap } } diff --git a/pico-env.cmd b/pico-env.cmd index 5ea4cc1..0554f24 100644 --- a/pico-env.cmd +++ b/pico-env.cmd @@ -52,7 +52,7 @@ call :AddToPath "%ProgramFiles%\Microsoft Visual Studio\Installer" rem https://github.com/microsoft/vswhere/wiki/Start-Developer-Command-Prompt -for /f "usebackq delims=" %%i in (`vswhere.exe -products * -requires "Microsoft.VisualStudio.Component.VC.CoreIde" -latest -property installationPath`) do ( +for /f "usebackq delims=" %%i in (`vswhere.exe -products * -requires "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" -latest -property installationPath`) do ( if exist "%%i\Common7\Tools\vsdevcmd.bat" ( call "%%i\Common7\Tools\vsdevcmd.bat" ) diff --git a/tests/setup-oldvs.ps1 b/tests/setup-oldvs.ps1 index bfe2978..33e8d59 100644 --- a/tests/setup-oldvs.ps1 +++ b/tests/setup-oldvs.ps1 @@ -20,6 +20,6 @@ $elapsed = Measure-Command { $process = Start-Process -FilePath ".\installers\$f Write-Host ("Finished in {0:hh':'mm':'ss}" -f $elapsed) if ($process.ExitCode -ne 0) { - Write-Host "Install failed with exit code $($process.ExitCode)" + throw "Install failed with exit code $($process.ExitCode)" exit $process.ExitCode }