blob: ce7e71efa31f6ce12b8158379d04f2a43e29687b [file] [log] [blame]
Steve Dower40a23e82017-06-19 10:34:25 -07001@rem
2@rem Searches for MSBuild.exe. This is the only tool we need to initiate
3@rem a build, so we no longer search for the full VC toolset.
4@rem
5@rem This file is supposed to modify the state of the caller (specifically
6@rem the MSBUILD variable), so we do not use setlocal or echo, and avoid
7@rem changing any other persistent state.
8@rem
9
10@rem No arguments provided means do full search
11@if '%1' EQU '' goto :begin_search
12
13@rem One argument may be the full path. Use a goto so we don't try to
14@rem parse the next if statement - incorrect quoting in the multi-arg
15@rem case can cause us to break immediately.
16@if '%2' EQU '' goto :one_arg
17
18@rem Entire command line may represent the full path if quoting failed.
19@if exist "%*" (set MSBUILD="%*") & (set _Py_MSBuild_Source=environment) & goto :found
20@goto :begin_search
21
22:one_arg
23@if exist "%~1" (set MSBUILD="%~1") & (set _Py_MSBuild_Source=environment) & goto :found
24
25:begin_search
26@set MSBUILD=
27
28@rem If msbuild.exe is on the PATH, assume that the user wants that one.
29@where msbuild > "%TEMP%\msbuild.loc" 2> nul && set /P MSBUILD= < "%TEMP%\msbuild.loc" & del "%TEMP%\msbuild.loc"
30@if exist "%MSBUILD%" set MSBUILD="%MSBUILD%" & (set _Py_MSBuild_Source=PATH) & goto :found
31
Steve Dower0cd63912018-12-10 18:52:57 -080032@rem VS 2017 and later provide vswhere.exe, which can be used
33@if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" goto :skip_vswhere
34@set _Py_MSBuild_Root=
Steve Dower894adc12020-03-11 23:24:30 +000035@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)
Steve Dower0cd63912018-12-10 18:52:57 -080036@if not defined _Py_MSBuild_Root goto :skip_vswhere
37@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")
38@set _Py_MSBuild_Root=
39@if defined MSBUILD @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio installation) & goto :found
40:skip_vswhere
41
Steve Dower881323d2018-02-27 22:09:27 -080042@rem VS 2015 and earlier register MSBuild separately, so we can find it.
43@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul
44@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 @(
45 @if "%%i"=="MSBuildToolsPath" @if exist "%%k\msbuild.exe" @(set MSBUILD="%%k\msbuild.exe")
46)
47@if exist %MSBUILD% (set _Py_MSBuild_Source=registry) & goto :found
48
Steve Dower40a23e82017-06-19 10:34:25 -070049
50@exit /b 1
51
52:found
Steve Dowere97ba4c2018-05-28 12:32:05 -070053@pushd %MSBUILD% >nul 2>nul
54@if not ERRORLEVEL 1 @(
55 @if exist msbuild.exe @(set MSBUILD="%CD%\msbuild.exe") else @(set MSBUILD=)
56 @popd
57)
58
59@if defined MSBUILD @echo Using %MSBUILD% (found in the %_Py_MSBuild_Source%)
60@if not defined MSBUILD @echo Failed to find MSBuild
Steve Dower40a23e82017-06-19 10:34:25 -070061@set _Py_MSBuild_Source=
Steve Dowere97ba4c2018-05-28 12:32:05 -070062@if not defined MSBUILD @exit /b 1
Steve Dowerf9b364f2018-05-28 14:05:05 -070063@exit /b 0