From 7660b8d6cfa21c132ff8b492323d2fbc221fec96 Mon Sep 17 00:00:00 2001 From: cmxl Date: Tue, 19 May 2026 10:22:24 +0200 Subject: [PATCH] fix(release): make MSBuild discovery resilient to newer VS lines release.ps1 relied on vswhere.exe to locate MSBuild, but the vswhere bundled with the VS Installer can pre-date newer VS lines (e.g. Dev18 / VS 2026) and return nothing for them. When that happens, $msBuildPath is null and Get-Command $msBuildPath raises: Cannot validate argument on parameter 'Name'. The argument is null or empty. Replace the single vswhere call with a Find-MSBuildPath function that: - Tries vswhere first (existing behavior preserved). - Falls back to scanning known install paths under "Microsoft Visual Studio\\\MSBuild\Current\Bin\MSBuild.exe" for VS 17 / 18 / 2022 / 2026 across BuildTools / Community / Professional / Enterprise editions. - Throws a clear error if neither approach finds MSBuild. Co-Authored-By: Claude --- release.ps1 | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/release.ps1 b/release.ps1 index 3277bb7d..3cf0c279 100644 --- a/release.ps1 +++ b/release.ps1 @@ -14,11 +14,32 @@ $ErrorActionPreference = 'Stop' $workingDir = $pwd Write-Output "Working directory: $workingDir" -# Find MSBuild. -$msBuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" ` - -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe ` - -prerelease | Select-Object -First 1 -Write-Output "MSBuild: $((Get-Command $msBuildPath).Path)" +# Find MSBuild. vswhere is preferred, but older bundled versions don't recognize +# newer VS lines (e.g. Dev18 / VS 2026), so we fall back to scanning known install paths. +function Find-MSBuildPath { + $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + if (Test-Path $vswhere) { + $found = & $vswhere -latest -prerelease ` + -requires Microsoft.Component.MSBuild ` + -find 'MSBuild\**\Bin\MSBuild.exe' | + Select-Object -First 1 + if ($found) { return $found } + } + $roots = @($env:ProgramFiles, ${env:ProgramFiles(x86)}) + $editions = 'BuildTools','Community','Professional','Enterprise' + foreach ($r in $roots) { + foreach ($ver in '18','2026','2022','17') { + foreach ($ed in $editions) { + $p = Join-Path $r "Microsoft Visual Studio\$ver\$ed\MSBuild\Current\Bin\MSBuild.exe" + if (Test-Path $p) { return $p } + } + } + } + throw 'MSBuild not found via vswhere or known paths.' +} + +$msBuildPath = Find-MSBuildPath +Write-Output "MSBuild: $msBuildPath" # Load current Git tag. $tag = $(git describe --tags)