Skip to content

Commit 0b7ae3e

Browse files
committed
Handle when Resolve-Path throws if VS2019 is not present
1 parent 5166559 commit 0b7ae3e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/common.lib.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ function Locate-MSBuildPath($hasVsixExtension = "false") {
5656
$vsInstallPath = Locate-VsInstallPath -hasVsixExtension $hasVsixExtension
5757

5858
# first try to find the VS2019+ path
59-
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\Current\Bin"
60-
$msbuildPath = Resolve-Path $msbuildPath
61-
62-
# otherwise fall back to the VS2017 path
63-
if(!(Test-Path -path $msbuildPath)) {
59+
try {
60+
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\Current\Bin"
61+
$msbuildPath = Resolve-Path $msbuildPath
62+
}
63+
catch {
64+
# Resolve-Path throws if the path does not exist, so use the VS2017 path as a fallback
6465
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\$msbuildVersion\Bin"
6566
$msbuildPath = Resolve-Path $msbuildPath
6667
}

0 commit comments

Comments
 (0)