Repository navigation
Expand file tree
/
Copy pathBuildWindowsPackages.bat
More file actions
228 lines (206 loc) · 6.43 KB
/
Copy pathBuildWindowsPackages.bat
File metadata and controls
228 lines (206 loc) · 6.43 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@echo off
setlocal EnableDelayedExpansion
set APP_NAME=ULogViewer
set DEFAULT_RID_LIST=win-x64 win-arm64
set RID_LIST=
set CONFIG=Release
set FRAMEWORK=net11.0
set SELF_CONTAINED=true
set TRIM_ASSEMBLIES=true
set TESTING_MODE_BUILD=false
set GENERATE_DIFF_PACKAGES=true
set RUN_TESTS=true
set TESTS_ONLY=false
REM Parse arguments
:parse_arguments
if "%~1"=="" goto arguments_parsed
if /I "%~1"=="-h" goto print_usage_and_exit
if /I "%~1"=="--help" goto print_usage_and_exit
if /I "%~1"=="--rid" goto parse_rid_argument
if /I "%~1"=="--config" (
if "%~2"=="" (
echo Missing value of '--config'
exit /b 1
)
set CONFIG=%~2
shift
shift
goto parse_arguments
)
if /I "%~1"=="--no-trim" (
set TRIM_ASSEMBLIES=false
shift
goto parse_arguments
)
if /I "%~1"=="--testing-mode" (
set TESTING_MODE_BUILD=true
shift
goto parse_arguments
)
if /I "%~1"=="--no-tests" (
set RUN_TESTS=false
shift
goto parse_arguments
)
if /I "%~1"=="--tests-only" (
set TESTS_ONLY=true
shift
goto parse_arguments
)
if /I "%~1"=="--no-diff-packages" (
set GENERATE_DIFF_PACKAGES=false
shift
goto parse_arguments
)
echo Unknown argument: %~1
echo.
call :print_usage
exit /b 1
REM Select the runtime identifier to build package for
:parse_rid_argument
if "%~2"=="" (
echo Missing value of '--rid'
exit /b 1
)
set IS_RID_SUPPORTED=false
for %%r in (%DEFAULT_RID_LIST%) do (
if /I "%%r"=="%~2" set IS_RID_SUPPORTED=true
)
if "%IS_RID_SUPPORTED%"=="false" (
echo Unsupported runtime identifier: %~2
echo Supported runtime identifiers: %DEFAULT_RID_LIST%
exit /b 1
)
set IS_RID_SELECTED=false
if not "%RID_LIST%"=="" (
for %%r in (%RID_LIST%) do (
if /I "%%r"=="%~2" set IS_RID_SELECTED=true
)
)
if "%IS_RID_SELECTED%"=="false" (
if "%RID_LIST%"=="" (
set RID_LIST=%~2
) else (
set RID_LIST=!RID_LIST! %~2
)
)
shift
shift
goto parse_arguments
REM Print usage of this script and exit
:print_usage_and_exit
call :print_usage
exit /b 0
REM Print usage of this script
:print_usage
echo Usage: BuildWindowsPackages.bat [options]
echo.
echo Options:
echo -h, --help Print this help message and exit.
echo --config ^<name^> Build configuration to use. (Default: %CONFIG%)
echo --rid ^<rid^> Runtime identifier to build package for, can be specified multiple times.
echo Supported: %DEFAULT_RID_LIST%. (Default: all of them)
echo --no-trim Do not trim assemblies while publishing the application.
echo --testing-mode Build the application in testing mode.
echo --no-tests Do not run test cases before building packages.
echo --tests-only Only run test cases without building packages.
echo --no-diff-packages Do not generate diff packages.
goto :eof
REM Select all runtime identifiers if none of them was specified
:arguments_parsed
if "%RID_LIST%"=="" set RID_LIST=%DEFAULT_RID_LIST%
REM Check conflict between arguments
if /I "%TESTS_ONLY%"=="true" (
if /I "%RUN_TESTS%"=="false" (
echo Cannot specify both '--no-tests' and '--tests-only'
exit /b 1
)
)
echo ********** Start building %APP_NAME% **********
REM Run test cases
if /I "%RUN_TESTS%"=="true" (
echo Run test cases
dotnet test %APP_NAME%.Tests -c %CONFIG%
if !ERRORLEVEL! neq 0 (
echo Test cases failed
exit /b 1
)
)
REM Stop if only test cases need to be run
if /I "%TESTS_ONLY%"=="true" exit /b 0
REM Create base directory
IF not exist Packages (
echo Create directory 'Packages'
mkdir Packages
if !ERRORLEVEL! neq 0 (
exit /b 1
)
)
REM Get current version
dotnet run PackagingTool.cs -- get-current-version %APP_NAME%\%APP_NAME%.csproj > Packages\Packaging.txt
if !ERRORLEVEL! neq 0 (
del /Q Packages\Packaging.txt
exit /b 1
)
set /p CURRENT_VERSION=<Packages\Packaging.txt
dotnet run PackagingTool.cs -- get-current-informational-version %APP_NAME%\%APP_NAME%.csproj > Packages\Packaging.txt
set /p CURRENT_INFORMATIONAL_VERSION=<Packages\Packaging.txt
set PACKAGE_VERSION=%CURRENT_VERSION%
if not [%CURRENT_INFORMATIONAL_VERSION%] == [] set PACKAGE_VERSION=%CURRENT_INFORMATIONAL_VERSION%
echo Version: %CURRENT_VERSION% (%PACKAGE_VERSION%)
REM Get previous version
if /I not "%GENERATE_DIFF_PACKAGES%"=="true" goto previous_version_checked
dotnet run PackagingTool.cs -- get-previous-version %APP_NAME%\%APP_NAME%.csproj > Packages\Packaging.txt
if !ERRORLEVEL! neq 0 (
del /Q Packages\Packaging.txt
exit /b 1
)
set /p PREVIOUS_VERSION=<Packages\Packaging.txt
if [%PREVIOUS_VERSION%] neq [] (
echo Previous version: %PREVIOUS_VERSION%
)
:previous_version_checked
REM Create output directory
if not exist Packages\%CURRENT_VERSION% (
echo Create directory 'Packages\%CURRENT_VERSION%'
mkdir Packages\%CURRENT_VERSION%
)
REM Build packages
(for %%r in (%RID_LIST%) do (
REM Start building slf-contained package
echo .
echo [%%r]
echo .
REM Clear project
if exist %APP_NAME%\bin\%CONFIG%\%FRAMEWORK%\%%r\publish\ (
echo Delete output directory '%APP_NAME%\bin\%CONFIG%\%FRAMEWORK%\%%r\publish'
rmdir %APP_NAME%\bin\%CONFIG%\%FRAMEWORK%\%%r\publish /s /q
)
REM Build project
dotnet publish %APP_NAME% -c %CONFIG% -r %%r --self-contained %SELF_CONTAINED% -p:PublishTrimmed=%TRIM_ASSEMBLIES% -p:TestingModeBuild=%TESTING_MODE_BUILD%
if !ERRORLEVEL! neq 0 (
echo Failed to build project: !ERRORLEVEL!
del /Q Packages\Packaging.txt
exit /b 1
)
if exist %APP_NAME%\bin\%CONFIG%\%FRAMEWORK%\%%r\publish\ULogViewer.png (
del /Q %APP_NAME%\bin\%CONFIG%\%FRAMEWORK%\%%r\publish\ULogViewer.png
)
REM Generate package
start /Wait PowerShell -ExecutionPolicy RemoteSigned -NoLogo -Command Compress-Archive -Force -Path %APP_NAME%\bin\%CONFIG%\%FRAMEWORK%\%%r\publish\* -DestinationPath Packages\%CURRENT_VERSION%\%APP_NAME%-%PACKAGE_VERSION%-%%r.zip
if !ERRORLEVEL! neq 0 (
echo Failed to generate package: !ERRORLEVEL!
del /Q Packages\Packaging.txt
exit /b 1
)
))
REM Generate diff packages
if /I "%GENERATE_DIFF_PACKAGES%"=="true" (
if [%PREVIOUS_VERSION%] neq [] (
dotnet run PackagingTool.cs -- create-diff-packages win %PREVIOUS_VERSION% %CURRENT_VERSION%
)
)
REM Generate package manifest
REM dotnet run PackagingTool.cs -- create-package-manifest win %APP_NAME% %CURRENT_VERSION%
REM Complete
del /Q Packages\Packaging.txt