11@ echo off
2- pushd %~dp0
32setlocal
43
54if exist bin goto Build
@@ -29,7 +28,7 @@ for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -p
2928 -requires Microsoft.Net.Component.4.5.2.TargetingPack ^
3029 -requires Microsoft.Net.Component.4.6.2.TargetingPack ^
3130 -property installationPath`) do (
32- set InstallDir = " %%i "
31+ set " InstallDir = %%i "
3332)
3433
3534if not DEFINED InstallDir (
@@ -38,49 +37,65 @@ if not DEFINED InstallDir (
3837 goto BuildFail
3938)
4039
41- REM Find or install MSBuild. Need v17.4 due to our .NET SDK choice.
40+ REM Find a 64bit MSBuild and add it to path. Require v17.4 or later due to our .NET SDK choice.
41+ REM Check for VS2022 first.
42+ set InstallDir =
43+ for /f " usebackq tokens=*" %%i in (`%vswhere% -version 17.4 -latest -prerelease -products * ^
44+ -requires Microsoft.Component.MSBuild ^
45+ -property installationPath`) do (
46+ set " InstallDir = %%i "
47+ )
48+
49+ if DEFINED InstallDir (
50+ REM Add MSBuild to the path.
51+ set " PATH = %InstallDir% \MSBuild\Current\Bin\amd64;%PATH% "
52+ goto FoundMSBuild
53+ )
54+
55+ REM Otherwise find or install an xcopy-able MSBuild.
56+ echo " Could not find a VS2022 installation with the necessary components (MSBuild). Falling back..."
57+
4258set " MSBuildVersion = 17.4.1"
4359set " Command = [System.Threading.Thread]::CurrentThread.CurrentCulture = ''"
4460set " Command = %Command% ; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''"
4561set " Command = %Command% ; try { & '%~dp0 eng\GetXCopyMSBuild.ps1' %MSBuildVersion% ; exit $LASTEXITCODE }"
4662set " Command = %Command% catch { write-host $_; exit 1 }"
47- PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command " %Command% "
63+ PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command " %Command% "
4864if %ERRORLEVEL% neq 0 goto BuildFail
4965
5066REM Add MSBuild to the path.
51- set " PATH = %CD% \ .msbuild\%MSBuildVersion% \tools\MSBuild\Current\Bin\;%PATH% "
67+ set " PATH = %~dp0 .msbuild\%MSBuildVersion% \tools\MSBuild\Current\Bin\amd64 ;%PATH% "
5268
69+ :FoundMSBuild
5370REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.
5471REM Note this causes two copies of packages restored using packages.config to land in this folder e.g.
5572REM StyleCpy.5.0.0/ and stylecop/5.0.0/.
56- set " NUGET_PACKAGES = %CD% \packages "
73+ set " NUGET_PACKAGES = %~dp0 packages "
5774
5875REM Are we running in a local dev environment (not on CI)?
5976if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop=false) else (set Desktop=true)
6077
6178if " %1 " == " " goto BuildDefaults
6279
63- MSBuild Runtime .msbuild /m /nr:false /p:Platform=" Any CPU" /p:Desktop=%Desktop% /v:M ^
80+ MSBuild " %~dp0 Runtime .msbuild" /m /nr:false /p:Platform=" Any CPU" /p:Desktop=%Desktop% /v:M ^
6481 /fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary /t:%*
6582if %ERRORLEVEL% neq 0 goto BuildFail
6683goto BuildSuccess
6784
6885:BuildDefaults
69- MSBuild Runtime .msbuild /m /nr:false /p:Platform=" Any CPU" /p:Desktop=%Desktop% /v:M ^
86+ MSBuild " %~dp0 Runtime .msbuild" /m /nr:false /p:Platform=" Any CPU" /p:Desktop=%Desktop% /v:M ^
7087 /fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary
7188if %ERRORLEVEL% neq 0 goto BuildFail
7289goto BuildSuccess
7390
7491:BuildFail
7592echo .
7693echo *** BUILD FAILED ***
77- popd
7894endlocal
7995exit /B 999
8096
8197:BuildSuccess
8298echo .
8399echo **** BUILD SUCCESSFUL ***
84- popd
85100endlocal
86101exit /B 0
0 commit comments