1
1
@ echo off
2
- pushd %~dp0
3
2
setlocal
4
3
5
4
if exist bin goto Build
@@ -29,7 +28,7 @@ for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -p
29
28
-requires Microsoft.Net.Component.4.5.2.TargetingPack ^
30
29
-requires Microsoft.Net.Component.4.6.2.TargetingPack ^
31
30
-property installationPath`) do (
32
- set InstallDir = " %%i "
31
+ set " InstallDir = %%i "
33
32
)
34
33
35
34
if not DEFINED InstallDir (
@@ -38,49 +37,65 @@ if not DEFINED InstallDir (
38
37
goto BuildFail
39
38
)
40
39
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
+
42
58
set " MSBuildVersion = 17.4.1"
43
59
set " Command = [System.Threading.Thread]::CurrentThread.CurrentCulture = ''"
44
60
set " Command = %Command% ; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''"
45
61
set " Command = %Command% ; try { & '%~dp0 eng\GetXCopyMSBuild.ps1' %MSBuildVersion% ; exit $LASTEXITCODE }"
46
62
set " Command = %Command% catch { write-host $_; exit 1 }"
47
- PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command " %Command% "
63
+ PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command " %Command% "
48
64
if %ERRORLEVEL% neq 0 goto BuildFail
49
65
50
66
REM 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% "
52
68
69
+ :FoundMSBuild
53
70
REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.
54
71
REM Note this causes two copies of packages restored using packages.config to land in this folder e.g.
55
72
REM StyleCpy.5.0.0/ and stylecop/5.0.0/.
56
- set " NUGET_PACKAGES = %CD% \packages "
73
+ set " NUGET_PACKAGES = %~dp0 packages "
57
74
58
75
REM Are we running in a local dev environment (not on CI)?
59
76
if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop=false) else (set Desktop=true)
60
77
61
78
if " %1 " == " " goto BuildDefaults
62
79
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 ^
64
81
/fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary /t:%*
65
82
if %ERRORLEVEL% neq 0 goto BuildFail
66
83
goto BuildSuccess
67
84
68
85
: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 ^
70
87
/fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary
71
88
if %ERRORLEVEL% neq 0 goto BuildFail
72
89
goto BuildSuccess
73
90
74
91
:BuildFail
75
92
echo .
76
93
echo *** BUILD FAILED ***
77
- popd
78
94
endlocal
79
95
exit /B 999
80
96
81
97
:BuildSuccess
82
98
echo .
83
99
echo **** BUILD SUCCESSFUL ***
84
- popd
85
100
endlocal
86
101
exit /B 0
0 commit comments