change msbuild tool search from manual check instead of using vswhere

This commit is contained in:
Tess Gauthier 2023-05-11 17:22:19 -04:00
parent 2812433868
commit 3687fcd2f2
1 changed files with 13 additions and 7 deletions

View File

@ -617,7 +617,6 @@ function Get-VisualStudioPath {
) )
$vsWherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $vsWherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vsWherePath) { if (Test-Path $vsWherePath) {
$requiredToolset = 'Microsoft.Component.MSBuild'
$requiredVCtools = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64' $requiredVCtools = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
if ($NativeHostArch -eq 'arm') { if ($NativeHostArch -eq 'arm') {
$requiredVCtools = 'Microsoft.VisualStudio.Component.VC.Tools.ARM' $requiredVCtools = 'Microsoft.VisualStudio.Component.VC.Tools.ARM'
@ -625,13 +624,20 @@ function Get-VisualStudioPath {
elseif ($NativeHostArch -eq 'arm64') { elseif ($NativeHostArch -eq 'arm64') {
$requiredVCtools = 'Microsoft.VisualStudio.Component.VC.Tools.ARM64' $requiredVCtools = 'Microsoft.VisualStudio.Component.VC.Tools.ARM64'
} }
write-host "$vsWherePath -latest -products * -requires $requiredToolset -requires $requiredVCtools -property installationPath" write-host "$vsWherePath -products * -requires $requiredVCtools -property installationPath"
$VSPath = (& $vsWherePath -latest -products * -requires $requiredToolset -requires $requiredVCtools -property installationPath) $VSPaths = (& $vsWherePath -products * -requires $requiredVCtools -property installationPath)
if ($null -ne $VSPath) { # for some reason, VSWhere does not seem to find MSBuild so check manually
return $VSPath if ($null -ne $VSPaths) {
foreach ($VSPath in $VSPaths) {
if (Get-MSBuildPath -VSInstallPath $VSPath) {
return $VSPath
}
}
# if none of the VS installs have MSBuild, then build cannot proceed
Write-BuildMsg -AsError -ErrorAction Stop -Message "Visual Studio with required components not found, please ensure Microsoft.VisualStudio.Workload.MSBuildTools are installed"
} }
else { else {
Write-BuildMsg -AsError -ErrorAction Stop -Message "Visual Studio with required components not found, please ensure both $requiredToolset & $requiredVCtools are installed" Write-BuildMsg -AsError -ErrorAction Stop -Message "Visual Studio with required components not found, please ensure $requiredVCtools are installed"
} }
} }
else { else {
@ -653,7 +659,7 @@ function Get-MSBuildPath {
$toolAvailable = Get-ChildItem -path $fullSearchPath\* -Filter "MSBuild.exe" -ErrorAction SilentlyContinue $toolAvailable = Get-ChildItem -path $fullSearchPath\* -Filter "MSBuild.exe" -ErrorAction SilentlyContinue
if($null -eq $toolAvailable) if($null -eq $toolAvailable)
{ {
Write-BuildMsg -AsError -ErrorAction Stop -Message "MSBuild not found, please install" return $null
} }
return $toolAvailable[0].FullName return $toolAvailable[0].FullName
} }