From f9697fb336b61f375c14a3c23d6460d1164e63e7 Mon Sep 17 00:00:00 2001 From: Jimmy Lewis Date: Mon, 23 Sep 2019 10:42:59 -0700 Subject: [PATCH] Handle when Resolve-Path throws if VS2019 is not present --- scripts/common.lib.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/common.lib.ps1 b/scripts/common.lib.ps1 index da24b1e1d0..4afb5e8a21 100644 --- a/scripts/common.lib.ps1 +++ b/scripts/common.lib.ps1 @@ -56,11 +56,12 @@ function Locate-MSBuildPath($hasVsixExtension = "false") { $vsInstallPath = Locate-VsInstallPath -hasVsixExtension $hasVsixExtension # first try to find the VS2019+ path - $msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\Current\Bin" - $msbuildPath = Resolve-Path $msbuildPath - - # otherwise fall back to the VS2017 path - if(!(Test-Path -path $msbuildPath)) { + try { + $msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\Current\Bin" + $msbuildPath = Resolve-Path $msbuildPath + } + catch { + # Resolve-Path throws if the path does not exist, so use the VS2017 path as a fallback $msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\$msbuildVersion\Bin" $msbuildPath = Resolve-Path $msbuildPath }