This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
build.cmd
114 lines (102 loc) · 4.39 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
@echo off
setlocal enabledelayedexpansion
set BatchFile=%0
set Root=%~dp0
set BuildConfiguration=Debug
set MSBuildTarget=All
set NodeReuse=true
set MultiProcessor=/m
set MSBuildAdditionalArguments=/m
: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=Build&&shift&& goto :ParseArguments
if /I "%1" == "/rebuild" set MSBuildTarget=Rebuild&&shift&& goto :ParseArguments
if /I "%1" == "/package" set MSBuildTarget=Package&&shift&& goto :ParseArguments
if /I "%1" == "/test" set MSBuildTarget=Test&&shift&& goto :ParseArguments
if /I "%1" == "/restore" set MSBuildTarget=Restore&&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 build.props /nologo /v:m /t:GetVsInstallRoot') 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
)
@echo on
msbuild /nologo /nodeReuse:%NodeReuse% /t:"%MSBuildTarget%" /p:target="%MSBuildTarget%" /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 Green "Build completed successfully, for full log see msbuild.log"
exit /b 0
:Usage
echo Usage: %BatchFile% [/build^|/rebuild^|/test^|/restore^] [/debug^|/release] [/no-node-reuse] [/no-multi-proc]
echo.
echo Build targets:
echo /build Perform build
echo /rebuild Perform a clean, then build
echo /package Packages the product
echo /test Builds and runs tests only
echo /restore Only restore NuGet packages
echo.
echo Build options:
echo /debug Perform debug build (default)
echo /release Perform release build
echo /no-node-reuse Prevents MSBuild from reusing existing MSBuild instances,
echo useful for avoiding unexpected behavior on build machines
echo /no-multi-proc No multi-proc build, useful for diagnosing build logs
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'"