8000 bpo-39930: Fix MSBuild detection for Build Tools (GH-18938) · python/cpython@35ae5d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 35ae5d9

Browse files
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. (cherry picked from commit 894adc1) Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent 03ac090 commit 35ae5d9

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

PCbuild/find_msbuild.bat

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,13 @@
3232
@rem VS 2017 and later provide vswhere.exe, which can be used
3333
@if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" goto :skip_vswhere
3434
@set _Py_MSBuild_Root=
35-
@for /F "tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest -prerelease') DO @(set _Py_MSBuild_Root=%%i\MSBuild)
35+
@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)
3636
@if not defined _Py_MSBuild_Root goto :skip_vswhere
3737
@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")
3838
@set _Py_MSBuild_Root=
3939
@if defined MSBUILD @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio installation) & goto :found
4040
:skip_vswhere
4141

42-
@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there.
43-
@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul
44-
@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 @(
45-
@if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe")
46-
)
47-
@if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found
48-
4942
@rem VS 2015 and earlier register MSBuild separately, so we can find it.
5043
@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul
5144
@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 @(

PCbuild/pyproject.props

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,41 @@ public override bool Execute() {
202202
</Target>
203203

204204

205-
<Target Name="FindVCRuntime" Returns="VCRuntimeDLL">
206-
<PropertyGroup Condition="$(PlatformToolset) != 'v140'">
207-
<VCRedistDir>$(VCInstallDir)\Redist\MSVC\$(VCToolsRedistVersion)\</VCRedistDir>
208-
<VCRedistDir Condition="$(Platform) == 'Win32'">$(VCRedistDir)x86\</VCRedistDir>
209-
<VCRedistDir Condition="$(Platform) != 'Win32'">$(VCRedistDir)$(Platform)\</VCRedistDir>
210-
</PropertyGroup>
205+
<Target Name="FindVCRedistDir">
206+
<!-- Hard coded path for VS 2015 -->
211207
<PropertyGroup Condition="$(PlatformToolset) == 'v140'">
212208
<VCRedistDir>$(VCInstallDir)\redist\</VCRedistDir>
209+
</PropertyGroup>
210+
211+
<!-- Search for version number in some broken Build Tools installs -->
212+
<ItemGroup Condition="$(VCRedistDir) == '' and $(VCToolsRedistVersion) == ''">
213+
<_RedistFiles Include="$(VCInstallDir)\Redist\MSVC\*\*.*" />
214+
</ItemGroup>
215+
<PropertyGroup Condition="$(VCRedistDir) == '' and $(VCToolsRedistVersion) == ''">
216+
<_RedistDir>%(_RedistFiles.Directory)</_RedistDir>
217+
<VCToolsRedistVersion>$([System.IO.Path]::GetFileName($(_RedistDir.Trim(`\`))))</VCToolsRedistVersion>
218+
</PropertyGroup>
219+
220+
<!-- Use correct path for VS 2017 and later -->
221+
<PropertyGroup Condition="$(VCRedistDir) == ''">
222+
<VCRedistDir>$(VCInstallDir)\Redist\MSVC\$(VCToolsRedistVersion)\</VCRedistDir>
223+
</PropertyGroup>
224+
225+
<PropertyGroup>
213226
<VCRedistDir Condition="$(Platform) == 'Win32'">$(VCRedistDir)x86\</VCRedistDir>
214227
<VCRedistDir Condition="$(Platform) != 'Win32'">$(VCRedistDir)$(Platform)\</VCRedistDir>
215228
</PropertyGroup>
216229

230+
<Message Text="VC Redist Directory: $(VCRedistDir)" />
231+
<Message Text="VC Redist Version: $(VCToolsRedistVersion)" />
232+
</Target>
233+
234+
<Target Name="FindVCRuntime" Returns="VCRuntimeDLL" DependsOnTargets="FindVCRedistDir&qu 6D1B ot;>
217235
<ItemGroup Condition="$(VCInstallDir) != ''">
218236
<VCRuntimeDLL Include="$(VCRedistDir)\Microsoft.VC*.CRT\vcruntime*.dll" />
219237
</ItemGroup>
220238

221-
<Warning Text="vcruntime14*.dll not found under $(VCInstallDir)" Condition="@(VCRuntimeDLL) == ''" />
222-
<Message Text="VCRuntimeDLL: @(VCRuntimeDLL)" Importance="high" />
239+
<Warning Text="vcruntime*.dll not found under $(VCRedistDir)." Condition="@(VCRuntimeDLL) == ''" />
240+
<Message Text="VC Runtime DLL(s):%0A- @(VCRuntimeDLL,'%0A- ')" />
223241
</Target>
224242
</Project>

0 commit comments

Comments
 (0)
0