blob: 2b7413fbcde87062c08c6a07603786dd56671fc1 [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 Dower68d663c2017-07-17 11:15:48 +020032@rem VS 2015 and earlier register MSBuild separately, so we can find it.
33@rem Prefer MSBuild 14.0 over MSBuild 15.0, since the latter may not be able to find a VC14 install.
34@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul
35@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 @(
36 @if "%%i"=="MSBuildToolsPath" @if exist "%%k\msbuild.exe" @(set MSBUILD="%%k\msbuild.exe")
37)
38@if exist %MSBUILD% (set _Py_MSBuild_Source=registry) & goto :found
39
Steve Dower40a23e82017-06-19 10:34:25 -070040@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there.
41@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul
42@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 @(
43 @if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe")
44)
45@if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found
46
Steve Dower40a23e82017-06-19 10:34:25 -070047
48@exit /b 1
49
50:found
51@echo Using %MSBUILD% (found in the %_Py_MSBuild_Source%)
52@set _Py_MSBuild_Source=