Fix MSBuild property for VS2019+ Current layout and instance-derived install dir - #5307
Open
CAOShurong wants to merge 1 commit into
Open
CAOShurong wants to merge 1 commit into
CAOShurong wants to merge 1 commit into
Conversation
…install dir The EnvironmentInfo.MSBuild property built paths as MSBuild/<vs_ver:0.1f>/bin for every version >= 15.0, but since Visual Studio 2019 (v16) the on-disk layout is the version-independent MSBuild/Current/bin. Additionally, vs_ver is a lossy major.minor float (17.12 -> "17.1"), so both the registry lookup key and the default path missed real installations; on a VS2022 17.12 machine every returned path was nonexistent. - Use MSBuild/Current/bin (+Roslyn) for vs_ver >= 16.0, keep the per-version layouts for VS2015 and VS2017. - Filter candidates to directories that exist when at least one does, so consumers do not receive dead paths. - Prefer the exact installationPath recorded in the Visual Studio installer instance state (known_vs_paths) in SystemInfo.VSInstallDir, avoiding the lossy float formatting entirely. Fixes pypa#5275 Signed-off-by: Shurong Cao <35021@users.noreply.github.com>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5275
Summary
The
EnvironmentInfo.MSBuildproperty has two independent defects on VS2019+ machines:vs_ver >= 15.0the property builds paths asMSBuild\<vs_ver>\bin, but since Visual Studio 2019 (v16) the on-disk layout is the version-independentMSBuild\Current\bin. The issue's reported VS2026 output (MSBuild\18.7\bin) and my local VS2022 output (MSBuild\17.1\bin) are both nonexistent directories produced by this branch.vs_veris amajor.minorfloat, so a real 17.12 install formats as"17.1". That string is used both as the registry lookup key (self.ri.lookup(self.ri.vs, f'{self.vs_ver:0.1f}')) — which finds nothing — and in the default path.VSInstallDirtherefore resolves to a directory that does not exist.Fix
MSBuild\Current\bin(+Roslyn) forvs_ver >= 16.0; keep the historical per-version layouts for VS2015 (C:\Program Files (x86)\MSBuild\14.0\bin, which never had the VS-directory prefix) and VS2017 (MSBuild\15.x\bin).installationPathrecorded by the Visual Studio installer instance state (SystemInfo.known_vs_paths, already parsed fromC:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\*\state.json) inSystemInfo.VSInstallDir, matching on major version. This avoids the lossy float formatting entirely.Validation
On this Windows 11 machine with VS2022 Community 17.12 installed:
Both post-fix paths contain
MSBuild.exe/ Roslyn binaries.Tests: new
setuptools/tests/test_msvc_msbuild.py(8 cases) covering VS2015/VS2017/VS2019/VS2022-multiline/VS2026 layouts, empty-result behavior for old versions, existence filtering, plus an opt-in real-environment check asserting every returned path exists when a genuine VS install is present. Red/green verified: 5 of the new cases fail on unpatchedmain, all 8 pass with the fix; existingsetuptools/_distutils/compilers/C/tests/test_msvc.pysuite still green (15 passed, 1 skipped).Signed-off-by: Shurong Cao 35021@users.noreply.github.com