Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions scripts/vs-shell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ if($env:VSINSTALLDIR -eq $null) {
throw "Command not found: vswhere (did you install Visual Studio?)"
}

$vsDir = (& $vswhere -prerelease -latest -property installationPath)
# -products * is required to also match Build Tools installs, which vswhere
# skips by default (a machine with only Build Tools would fall through to the
# hardcoded 2022 paths and miss newer toolsets entirely). Require the C++
# toolset for the target arch so an install without it can't be selected.
$vcTools = if ($script:IsARM64) { "Microsoft.VisualStudio.Component.VC.Tools.ARM64" } else { "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" }
$vsDir = (& $vswhere -products * -requires $vcTools -prerelease -latest -property installationPath)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if ($vsDir -eq $null) {
# Check common VS installation paths
$searchPaths = @(
Expand All @@ -24,7 +29,11 @@ if($env:VSINSTALLDIR -eq $null) {
)
foreach ($searchPath in $searchPaths) {
if (Test-Path $searchPath) {
$vsDir = (Get-ChildItem -Path $searchPath -Directory | Select-Object -First 1).FullName
# Only accept an install that actually ships the C++ toolset (vswhere
# isn't usable here, so check for the toolset directory instead).
$vsDir = (Get-ChildItem -Path $searchPath -Directory |
Where-Object { Test-Path (Join-Path $_.FullName "VC\Tools\MSVC") } |
Select-Object -First 1).FullName
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if ($vsDir -ne $null) { break }
}
}
Expand Down