-
Notifications
You must be signed in to change notification settings - Fork 50
/
build.cmd
93 lines (77 loc) · 3.6 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
@echo off
setlocal
if "%~1"=="/?" goto :Help
if "%~1"=="-?" goto :Help
if "%~1"=="-h" goto :Help
set AdditionalBuildArgs=%*
if NOT "%VSINSTALLDIR%"=="" goto InDevPrompt
set x86ProgramFiles=%ProgramFiles(x86)%
if "%x86ProgramFiles%"=="" set x86ProgramFiles=%ProgramFiles%
set VSWherePath=%x86ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe
if NOT exist "%VSWherePath%" echo ERROR: Could not find vswhere.exe (%VSWherePath%). Ensure that Visual Studio 2022 or newer is installed. & exit /b -1
for /f "usebackq tokens=1 delims=" %%a in (`"%VSWherePath%" -version [17.0, -prerelease -requires Microsoft.VisualStudio.Workload.NativeDesktop;Microsoft.VisualStudio.Workload.VisualStudioExtension;Microsoft.VisualStudio.Workload.ManagedDesktop -property installationPath`) do call :ProcessIDE "%%a"
if NOT "%VSINSTALLDIR%"=="" goto InDevPrompt
echo ERROR: Unable to find a Visual Studio 2022 or newer install.
exit /b -1
:InDevPrompt
pushd %~dp0
del /s msbuild.log 2>NUL
set BuildError=
call :SetNugetPath nuget.exe
call :RestoreFromSLN Iris\Iris.sln
call :RestoreFromSLN HelloWorld\cs\HelloWorld.sln
call :RestoreFromPackagesConfig CppCustomVisualizer\dll\packages.config CppCustomVisualizer\packages
call :RestoreFromPackagesConfig CppCustomVisualizer2\dll\packages.config CppCustomVisualizer2\packages
call :RestoreFromPackagesConfig HelloWorld\Cpp\dll\packages.config HelloWorld\Cpp\packages
call :Build Iris\Iris.sln Iris "Any CPU"
call :Build HelloWorld\cs\HelloWorld.sln CsHelloWorld "Any CPU"
call :Build HelloWorld\cpp\HelloWorld.sln CppHelloWorld x64
call :Build CppCustomVisualizer\CppCustomVisualizer.sln CppCustomVisualizer x64
call :Build CppCustomVisualizer2\CppCustomVisualizer.sln CppCustomVisualizer x64
if NOT "%BuildError%"=="" exit /b -1
echo build.cmd completed successfully.
exit /b 0
:RestoreFromPackagesConfig
if NOT "%BuildError%"=="" goto :EOF
set NugetCmd="%NUGET_EXE%" restore %1 -PackagesDirectory %2
echo %NugetCmd%
call %NugetCmd%
if NOT "%ERRORLEVEL%"=="0" echo ERROR: build.cmd: Restoring %1 failed.& set BuildError=1
goto :EOF
:RestoreFromSLN
if NOT "%BuildError%"=="" goto :EOF
set NugetCmd="%NUGET_EXE%" restore %1
echo %NugetCmd%
call %NugetCmd%
if NOT "%ERRORLEVEL%"=="0" echo ERROR: build.cmd: Restoring %1 failed.& set BuildError=1
goto :EOF
:Build
if NOT "%BuildError%"=="" goto :EOF
REM NOTE: To enable binary logs, add: `/bl:%2.binlog` after `%1`
set MSBuildCmd=msbuild.exe %1 /nologo /maxcpucount /nodeReuse:false /p:Platform=%3 %AdditionalBuildArgs%
echo %MSBuildCmd%
call %MSBuildCmd%
if NOT "%ERRORLEVEL%"=="0" echo ERROR: build.cmd: Building %1 failed.& set BuildError=1
goto :EOF
:SetNugetPath
set NUGET_EXE=%~$PATH:1
if NOT "%NUGET_EXE%"=="" goto :EOF
if exist obj\nuget.exe set NUGET_EXE=%~dp0obj\nuget.exe& goto :EOF
if not exist obj mkdir obj
call powershell.exe -NoProfile -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile obj\nuget.exe"
if NOT "%ERRORLEVEL%"=="0" echo ERROR: build.cmd: Downloading nuget.exe failed.& set BuildError=1& goto :EOF
if NOT exist obj\nuget.exe echo ERROR: build.cmd: nuget.exe is unexpectedly missing.& set BuildError=1& goto :EOF
set NUGET_EXE=%~dp0obj\nuget.exe
goto :EOF
:ProcessIDE
if NOT "%VSINSTALLDIR%"=="" goto :EOF
if NOT exist "%~1\Common7\Tools\VsDevCmd.bat" goto :EOF
echo Using Visual Studio from %1
call "%~1\Common7\Tools\VsDevCmd.bat"
goto :EOF
:Help
echo Build.cmd [Additional msbuild arguments]
echo.
echo This script restores and builds all projects in this repo.
echo.
echo Example usage: build.cmd /p:Configuration=Debug