Skip to content

fix(windows): detect MSBuild in VS BuildTools editions - #117

Merged
oransel merged 1 commit into
oransel:masterfrom
AlexRMU:fix/msbuild-buildtools-detection
Oct 6, 2026
Merged

oransel merged 1 commit into
oransel:masterfrom
AlexRMU:fix/msbuild-buildtools-detection

Conversation

@AlexRMU

@AlexRMU AlexRMU commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #116.

Problem

src/lib/build.js fails with MSBuild not found. Please install Visual Studio Build Tools. even when Build Tools is installed, because:

  1. The vswhere call omits -products *, so BuildTools installations are invisible to it (vswhere only reports full VS editions by default).
  2. The hardcoded possiblePaths fallback list covers only Enterprise/Professional/Community editions — no BuildTools entries, even though Build Tools is the edition Microsoft recommends for CI and what choco install visualstudio2022-workload-vctools / winget produce.
  3. PlatformToolset=v143 is hardcoded, which fails with MSB8020 when MSBuild is found under VS 2019 (v142) or VS 2017 (v141).

Changes

  • vswhere: add -products * and require Microsoft.VisualStudio.Component.VC.Tools.x86.x64 instead of Microsoft.Component.MSBuild — this both finds BuildTools installs and guarantees a C++ toolchain is present (bare MSBuild without VC tools cannot build the addon).
  • Fallback: replace the hardcoded list with a scan over Program Files/Program Files (x86) × years 2022/2019/2017 × editions Enterprise/Professional/Community/BuildTools (plus the legacy MSBuild\14.0 paths). 2017 uses the MSBuild\15.0\Bin layout, 2019+ use MSBuild\Current\Bin.
  • Toolset: derive PlatformToolset from the VS year in the resolved MSBuild path (2017 → v141, 2019 → v142, default v143) instead of hardcoding v143.

Verification

  • node --check src/lib/build.js passes.
  • Tested on Windows with VS 2022 BuildTools (C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools, MSVC 14.44, SDK 10.0.26100.0): the vswhere path now resolves the BuildTools install directly — no directory-junction workaround (mklink /J ... Community ... BuildTools) needed anymore.
  • The same logic has been running as a downstream pnpm patch (patchedDependencies) in a production project since 2026-08 across VS 2019 BuildTools and VS 2022 BuildTools machines, Windows and Docker/Linux CI.

- vswhere: add -products * so BuildTools installs are visible, and require
  Microsoft.VisualStudio.Component.VC.Tools.x86.x64 to guarantee a C++
  toolchain is present (bare MSBuild is not enough to build the addon)
- fallback: scan roots x years x editions (incl. BuildTools) instead of a
  hardcoded list that only covered Enterprise/Professional/Community
- derive PlatformToolset from the VS year in the MSBuild path
  (2017 -> v141, 2019 -> v142, default v143) instead of hardcoding v143,
  which fails with MSB8020 on VS 2019

Fixes oransel#116
@oransel
oransel merged commit ba90a91 into oransel:master Oct 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows build fails with "MSBuild not found" when only VS Build Tools is installed (possiblePaths list has no BuildTools entries)

2 participants