Skip to content

Commit ca150da

Browse files
committed
fix(windows): discover MSBuild in CI
1 parent ab26ada commit ca150da

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

scripts/build-windows.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,21 @@ if ($LASTEXITCODE -ne 0) { throw "CMake build failed" }
5959
if ($BuildWinUI) {
6060
$msbuild = Get-Command msbuild.exe -ErrorAction SilentlyContinue
6161
if ($null -eq $msbuild) {
62-
throw "MSBuild was not found. Run from a Visual Studio 2022 developer environment."
62+
$vswhere = Join-Path ${env:ProgramFiles(x86)} `
63+
"Microsoft Visual Studio/Installer/vswhere.exe"
64+
if (Test-Path -LiteralPath $vswhere) {
65+
$installationPath = & $vswhere -latest -products * `
66+
-requires Microsoft.Component.MSBuild -property installationPath
67+
if ($LASTEXITCODE -eq 0 -and $installationPath) {
68+
$candidate = Join-Path $installationPath "MSBuild/Current/Bin/MSBuild.exe"
69+
if (Test-Path -LiteralPath $candidate) {
70+
$msbuild = Get-Item -LiteralPath $candidate
71+
}
72+
}
73+
}
74+
}
75+
if ($null -eq $msbuild) {
76+
throw "MSBuild was not found in PATH or a Visual Studio 2022 installation."
6377
}
6478
$winUIPlatform = switch -Wildcard ($RustTarget) {
6579
"aarch64-*" { "ARM64"; break }
@@ -76,7 +90,8 @@ if ($BuildWinUI) {
7690
"/p:Platform=$winUIPlatform",
7791
"/p:LitheRustCoreLibrary=$($rustLibrary.FullName)"
7892
)
79-
& $msbuild.Source @msbuildArgs
93+
$msbuildPath = if ($msbuild.Source) { $msbuild.Source } else { $msbuild.FullName }
94+
& $msbuildPath @msbuildArgs
8095
if ($LASTEXITCODE -ne 0) { throw "WinUI 3 build failed" }
8196
}
8297

0 commit comments

Comments
 (0)