-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.cmd
126 lines (112 loc) · 5.05 KB
/
build.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@echo off
setlocal enabledelayedexpansion
:: Perf/usability tweaks for MSBuild
set MSBUILDLOGASYNC=1
set MSBUILDLOGTASKINPUTS=1
set MSBUILDDISABLENODEREUSE=1
set BatchFile=%0
set Root=%~dp0
set NodeReuse=true
set MultiProcessor=/m
set BuildConfiguration=
set MSBuildTarget=
set MSBuildAdditionalArguments=
:ParseArguments
if "%1" == "" goto :DoneParsing
if /I "%1" == "/?" call :Usage && exit /b 1
if /I "%1" == "/debug" set BuildConfiguration=Debug&&shift&& goto :ParseArguments
if /I "%1" == "/release" set BuildConfiguration=Release&&shift&& goto :ParseArguments
if /I "%1" == "/build" set MSBuildTarget=/t:Build&&shift&& goto :ParseArguments
if /I "%1" == "/clean" set MSBuildTarget=/t:Clean&&shift&& goto :ParseArguments
if /I "%1" == "/rebuild" set MSBuildTarget=/t:Rebuild&&shift&& goto :ParseArguments
if /I "%1" == "/restore" set MSBuildTarget=/t:Restore&&shift&& goto :ParseArguments
if /I "%1" == "/update" set MSBuildTarget=/t:Update&&shift&& goto :ParseArguments
if /I "%1" == "/test" set MSBuildTarget=/t:Test&&shift&& goto :ParseArguments
if /I "%1" == "/no-node-reuse" set NodeReuse=false&&shift&& goto :ParseArguments
if /I "%1" == "/no-multi-proc" set MultiProcessor=&&shift&& goto :ParseArguments
set MSBuildAdditionalArguments=%MSBuildAdditionalArguments% %1&&shift&& goto :ParseArguments
:DoneParsing
:: Detect if MSBuild is in the path
for /f "delims=" %%i in ('where msbuild') do set "MSBuildPath=%%i" & goto :MSBuildPathDone
:MSBuildPathDone
if not exist "%MSBuildPath%" (
call :PrintColor Red "To build this repository, MSBuild.exe must be in the PATH."
echo MSBuild is included with Visual Studio 2017 or later.
echo.
echo If Visual Studio is not installed, visit this page to download:
echo.
echo https://www.visualstudio.com/vs/
echo.
exit /b 1
)
:: Detect MSBuild version >= 15
for /f "delims=" %%i in ('msbuild -nologo -version') do set MSBuildFullVersion=%%i
for /f "delims=. tokens=1" %%a in ("%MSBuildFullVersion%") do (
set MSBuildMajorVersion=%%a
)
if %MSBuildMajorVersion% LSS 15 (
call :PrintColor Red "To build this repository, the MSBuild.exe in the PATH needs to be 15.0 or higher."
echo MSBuild 15.0 is included with Visual Studio 2017 or later.
echo.
echo If Visual Studio is not installed, visit this page to download:
echo.
echo https://www.visualstudio.com/vs/
echo.
echo Located MSBuild in the PATH was "%MSBuildPath%".
exit /b 1
)
:: Ensure developer command prompt variables are set
if "%VisualStudioVersion%" == "" (
for /f "delims=" %%i in ('msbuild -nologo %Root%corebuild\corebuild.targets /t:_GetVsInstallRoot /v:minimal') do set "VsInstallRoot=%%i" & goto :VsInstallRootDone
:VsInstallRootDone
for /f "tokens=* delims= " %%i in ("%VsInstallRoot%") do set "VsInstallRoot=%%i"
set "DeveloperCommandPrompt=%VsInstallRoot%\Common7\Tools\VsDevCmd.bat"
if not exist "%DeveloperCommandPrompt%" (
call :PrintColor Red "Failed to locate 'Common7\Tools\VsDevCmd.bat' under the reported Visual Studio installation root '%VsInstallRoot%'."
echo.
echo If Visual Studio is not installed, visit this page to download:
echo.
echo https://www.visualstudio.com/vs/
echo.
exit /b 1
)
call "%DeveloperCommandPrompt%" || goto :BuildFailed
)
if not "%MSBuildTarget%" == "" set MSBuildTargetName=%MSBuildTarget:~3%
@echo on
msbuild "%Root%build.proj" /nologo /nr:%NodeReuse% %MultiProcessor% %MSBuildTarget% /p:target=%MSBuildTargetName% /p:Configuration=%BuildConfiguration% %MSBuildAdditionalArguments%
@echo off
if ERRORLEVEL 1 (
echo.
call :PrintColor Red "Build failed, for full log see msbuild.log."
exit /b 1
)
echo.
call :PrintColor Cyan "Build completed successfully, for full log see msbuild.log"
exit /b 0
:Usage
echo Usage: %BatchFile% [/build^|/clean^|/rebuild^|/restore^|/update^|/test^] [/debug^|/release] [/no-node-reuse] [/no-multi-proc] [OPTIONS]
echo.
echo Build targets:
echo /build Builds the project
echo /clean Cleans a previous build
echo /rebuild Cleans, then builds
echo /restore Only restore NuGet packages
echo /update Updates corebuild targets and dependencies
echo /test Runs tests
echo.
echo Build options:
echo /debug Perform debug build (/p:Configuration=Debug)
echo /release Perform release build (/p:Configuration=Release)
echo /no-node-reuse Prevents MSBuild from reusing existing MSBuild instances,
echo useful for avoiding unexpected behavior on build machines ('/nr:false' switch)
echo /no-multi-proc No multi-proc build, useful for diagnosing build logs (no '/m' switch)
echo /noautoresponse Do not process the msbuild.rsp response file options
echo
echo [OPTIONS] Arbitrary MSBuild switches can also be passed in.
goto :eof
:BuildFailed
call :PrintColor Red "Build failed with ERRORLEVEL %ERRORLEVEL%"
exit /b 1
:PrintColor
"%Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe" -noprofile write-host -foregroundcolor %1 "'%2'"