Skip to content

fix: "Invalid version" for MSBuild 18.0 and pre-v12 versions - #14

Merged
jmkcoder merged 3 commits into
mainfrom
copilot/fix-msbuild-invalid-version
Mar 21, 2026
Merged

jmkcoder merged 3 commits into
mainfrom
copilot/fix-msbuild-invalid-version

Conversation

Copilot AI commented Mar 21, 2026 •

Copy link
Copy Markdown

findVersion() threw Invalid version for any toolsVersion due to two independent bugs in msbuild-finder.ts.

Bugs fixed

Pre-v12 versions incorrectly required vswhere.exe

Versions 1.0–4.0 live under C:\Windows\Microsoft.Net\Framework[64]\ — vswhere has no knowledge of them. The old code always called vswhere first; without it, findVersion() returned null.

Fix: Short-circuit for parsedNumber < 12 — call concatPreV12() and check the path directly, no vswhere involved.

V16+ detection used fragile path-substring matching

concatV16AndAbove checked installationPath.includes(MSBUILD_VERSIONS[version]). Works for v16/v17 because VS puts the year (2019, 2022) in the folder. For v18 the mapped value is '18' — any VS whose install folder doesn't contain the literal string '18' (e.g., a future Visual Studio 2026) silently returns '', producing null → Invalid version.

Fix: For major ≥ 16, find the matching installation using installationVersion from the vswhere JSON instead of path substring matching:

const matchingInstallation = installations.find((installation: any) => {
    const installMajor = parseInt(
        (installation.installationVersion || '').split('.')[0] || '0'
    );
    return installMajor === major;
});

This correctly resolves any present or future VS major version regardless of its folder naming convention. concatV16AndAbove and MSBUILD_VERSIONS are left intact as utility helpers.

Original prompt

This section details on the original issue you should resolve

<issue_title>Doesn't work with MSBuild 18.0</issue_title>
<issue_description>It keeps saying Invalid version no matter what I supply as toolsVersion.</issue_description>

<agent_instructions>It keeps saying Invalid version no matter what I supply as toolsVersion</agent_instructions>

Comments on the Issue (you are @copilot in this section)


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Copilot AI and others added 2 commits March 21, 2026 19:01
Co-authored-by: jmkcoder <149906506+jmkcoder@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jmkcoder/gulp-msbuild/sessions/9c8ee201-5404-440a-8d0c-79cdaf5c2aa6
- Pre-v12 versions (1.0-4.0) no longer require vswhere.exe; they are
  found directly in the .NET Framework directory
- V16+ version detection now matches installations by the major number
  in `installationVersion` (from vswhere JSON), replacing the fragile
  path-substring check that failed when VS 18's folder name doesn't
  contain '18'
- Add 7 new tests covering pre-v12 handling, v18/v16/v17 by
  installationVersion, and auto-detection of VS 18

Co-authored-by: jmkcoder <149906506+jmkcoder@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jmkcoder/gulp-msbuild/sessions/9c8ee201-5404-440a-8d0c-79cdaf5c2aa6
Copilot AI changed the title [WIP] Fix invalid toolsVersion issue with MSBuild 18.0 Fix "Invalid version" for MSBuild 18.0 and pre-v12 versions Mar 21, 2026
Copilot AI requested a review from jmkcoder March 21, 2026 19:06
@jmkcoder jmkcoder changed the title Fix "Invalid version" for MSBuild 18.0 and pre-v12 versions fix: "Invalid version" for MSBuild 18.0 and pre-v12 versions Mar 21, 2026
@jmkcoder
jmkcoder marked this pull request as ready for review March 21, 2026 19:17
@jmkcoder
jmkcoder merged commit fda21dd into main Mar 21, 2026
1 check passed
@jmkcoder
jmkcoder deleted the copilot/fix-msbuild-invalid-version branch March 21, 2026 19:19
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.

Doesn't work with MSBuild 18.0

2 participants