1@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 32@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= 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) 36@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 42@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 49 50@exit /b 1 51 52:found 53@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 61@set _Py_MSBuild_Source= 62@if not defined MSBUILD @exit /b 1 63@exit /b 0 64