From 894adc18b4fb7246b762276a50a332c0e4f0e0f0 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 11 Mar 2020 23:24:30 +0000 Subject: [PATCH] bpo-39930: Fix MSBuild detection for Build Tools (GH-18938) Ensure we detect Build Tools installs using the newer logic, and skip looking in the registry for VS 2017. --- PCbuild/find_msbuild.bat | 9 +-------- PCbuild/pyproject.props | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/PCbuild/find_msbuild.bat b/PCbuild/find_msbuild.bat index bc9d00c22c8..ce7e71efa31 100644 --- a/PCbuild/find_msbuild.bat +++ b/PCbuild/find_msbuild.bat @@ -32,20 +32,13 @@ @rem VS 2017 and later provide vswhere.exe, which can be used @if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" goto :skip_vswhere @set _Py_MSBuild_Root= -@for /F "tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest -prerelease') DO @(set _Py_MSBuild_Root=%%i\MSBuild) +@for /F "tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64') DO @(set _Py_MSBuild_Root=%%i\MSBuild) @if not defined _Py_MSBuild_Root goto :skip_vswhere @for %%j in (Current 15.0) DO @if exist "%_Py_MSBuild_Root%\%%j\Bin\msbuild.exe" (set MSBUILD="%_Py_MSBuild_Root%\%%j\Bin\msbuild.exe") @set _Py_MSBuild_Root= @if defined MSBUILD @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio installation) & goto :found :skip_vswhere -@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there. -@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul -@if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32') DO @( - @if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe") -) -@if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found - @rem VS 2015 and earlier register MSBuild separately, so we can find it. @reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul @if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32') DO @( diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props index 061c2253bcf..bb918b28e90 100644 --- a/PCbuild/pyproject.props +++ b/PCbuild/pyproject.props @@ -201,23 +201,41 @@ public override bool Execute() { - - - $(VCInstallDir)\Redist\MSVC\$(VCToolsRedistVersion)\ - $(VCRedistDir)x86\ - $(VCRedistDir)$(Platform)\ - + + $(VCInstallDir)\redist\ + + + + + <_RedistFiles Include="$(VCInstallDir)\Redist\MSVC\*\*.*" /> + + + <_RedistDir>%(_RedistFiles.Directory) + $([System.IO.Path]::GetFileName($(_RedistDir.Trim(`\`)))) + + + + + $(VCInstallDir)\Redist\MSVC\$(VCToolsRedistVersion)\ + + + $(VCRedistDir)x86\ $(VCRedistDir)$(Platform)\ + + + + + - - + +