Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
372 lines (321 loc) · 13.7 KB
/
Copy pathbuild.ps1
File metadata and controls
372 lines (321 loc) · 13.7 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# build.ps1 - DevOps Tools Installer (WinUI 3 + .NET 8)
#
# Usage:
# .\build.ps1 - Release build (folder output)
# .\build.ps1 -Configuration Debug
# .\build.ps1 -SingleFile - Produces a merged .exe
# .\build.ps1 -Run - Build then launch
# .\build.ps1 -Clean - Delete all build artifacts
param(
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Release',
[switch]$SingleFile,
[switch]$Setup,
[switch]$Msi,
[switch]$Msix,
[switch]$Run,
[switch]$Clean
)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$project = Join-Path $root 'src\DevOpsToolsInstaller\DevOpsToolsInstaller.csproj'
$pubDir = Join-Path $root "src\DevOpsToolsInstaller\bin\x64\$Configuration\net8.0-windows10.0.26100.0\win-x64\publish"
$exe = Join-Path $pubDir 'DevOpsToolsInstaller.exe'
function Write-Step([string]$msg) {
Write-Host ""
Write-Host " >> $msg" -ForegroundColor Cyan
}
function Write-Ok([string]$msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
function Write-Err([string]$msg) { Write-Host " [ERR] $msg" -ForegroundColor Red }
function Write-Warn([string]$msg) { Write-Host " [!] $msg" -ForegroundColor Yellow }
function Find-Dotnet {
if (Get-Command dotnet -ErrorAction SilentlyContinue) { return 'dotnet' }
$candidates = @(
'C:\Program Files\dotnet\dotnet.exe',
'C:\Program Files (x86)\dotnet\dotnet.exe',
"$env:LOCALAPPDATA\Microsoft\dotnet\dotnet.exe"
)
foreach ($c in $candidates) {
if (Test-Path $c) {
$env:PATH = ([IO.Path]::GetDirectoryName($c)) + ';' + $env:PATH
return $c
}
}
return $null
}
function Find-ISCC {
if (Get-Command ISCC.exe -ErrorAction SilentlyContinue) { return 'ISCC.exe' }
$candidates = @(
"$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe",
'C:\Program Files (x86)\Inno Setup 6\ISCC.exe',
'C:\Program Files\Inno Setup 6\ISCC.exe'
)
foreach ($c in $candidates) {
if (Test-Path $c) { return $c }
}
return $null
}
function Find-WiX {
if (Get-Command wix -ErrorAction SilentlyContinue) { return 'wix' }
$userTools = "$env:USERPROFILE\.dotnet\tools\wix.exe"
if (Test-Path $userTools) {
$env:PATH = "$env:USERPROFILE\.dotnet\tools;" + $env:PATH
return $userTools
}
return $null
}
# ---------------------------------------------------------------------------
# Clean
# ---------------------------------------------------------------------------
if ($Clean) {
Write-Step "Cleaning build artifacts..."
foreach ($d in @('src\DevOpsToolsInstaller\bin', 'src\DevOpsToolsInstaller\obj')) {
$full = Join-Path $root $d
if (Test-Path $full) {
Remove-Item -Path $full -Recurse -Force
Write-Ok "Removed $full"
}
}
Write-Host ""
Write-Host " Clean complete." -ForegroundColor Green
exit 0
}
# ---------------------------------------------------------------------------
# Banner
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "+------------------------------------------------------------------+" -ForegroundColor Cyan
Write-Host "| DevOps Tools Installer - Build Script (WinUI 3 / .NET 8) |" -ForegroundColor Cyan
Write-Host "+------------------------------------------------------------------+" -ForegroundColor Cyan
Write-Host ""
Write-Host " Configuration : $Configuration" -ForegroundColor White
Write-Host " Single File : $SingleFile" -ForegroundColor White
Write-Host " Setup Wizard : $Setup" -ForegroundColor White
Write-Host " MSI Package : $Msi" -ForegroundColor White
Write-Host " MSIX Package : $Msix" -ForegroundColor White
Write-Host " Project : $project" -ForegroundColor Gray
Write-Host ""
# ---------------------------------------------------------------------------
# Prerequisites
# ---------------------------------------------------------------------------
Write-Step "Checking prerequisites..."
$dotnet = Find-Dotnet
if (-not $dotnet) {
Write-Err ".NET SDK not found."
Write-Host " Install .NET 8 SDK: https://dotnet.microsoft.com/download/dotnet/8.0" -ForegroundColor Yellow
exit 1
}
$dotnetVersion = (& $dotnet --version 2>&1) | Out-String
$dotnetVersion = $dotnetVersion.Trim()
Write-Ok ".NET SDK $dotnetVersion"
$major = [int]($dotnetVersion -split '\.')[0]
if ($major -lt 8) {
Write-Err ".NET 8.0 or higher required (found $dotnetVersion)"
exit 1
}
if (-not (Test-Path $project)) {
Write-Err "Project not found: $project"
exit 1
}
Write-Ok "Project file found"
$catalogPath = Join-Path $root 'catalog\catalog.json'
if (Test-Path $catalogPath) {
Write-Ok "catalog.json found"
} else {
Write-Warn "catalog.json not found at $catalogPath"
}
Write-Ok "Prerequisites passed"
# ---------------------------------------------------------------------------
# Restore
# ---------------------------------------------------------------------------
Write-Step "Restoring NuGet packages..."
$restoreOut = & $dotnet restore $project -r win-x64 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Err "Restore failed:"
$restoreOut | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
exit 1
}
Write-Ok "Packages restored"
# ---------------------------------------------------------------------------
# Publish
# ---------------------------------------------------------------------------
Write-Step "Publishing ($Configuration, win-x64, self-contained)..."
$publishArgs = [System.Collections.Generic.List[string]]@(
'publish', $project,
'-c', $Configuration,
'-r', 'win-x64',
'--self-contained', 'true',
'--no-restore',
'-p:WindowsAppSDKSelfContained=true',
'-p:Platform=x64'
)
if ($SingleFile) {
$publishArgs.Add('-p:PublishSingleFile=true')
$publishArgs.Add('-p:IncludeNativeLibrariesForSelfExtract=true')
$publishArgs.Add('-p:EnableCompressionInSingleFile=true')
Write-Warn "Single-file: Windows App SDK runtime may still extract DLLs on first run"
}
$buildOut = & $dotnet @publishArgs 2>&1
$buildOut | ForEach-Object {
$line = "$_"
if ($line -match ' error ') {
Write-Host " $line" -ForegroundColor Red
} elseif ($line -match ' warning ') {
Write-Host " $line" -ForegroundColor Yellow
}
}
if ($LASTEXITCODE -ne 0) {
Write-Err "Publish failed - see output above."
exit 1
}
# ---------------------------------------------------------------------------
# Verify output
# ---------------------------------------------------------------------------
Write-Step "Verifying output..."
if (-not (Test-Path $exe)) {
Write-Err "Expected exe not found: $exe"
if (Test-Path $pubDir) {
Write-Warn "Publish dir contents:"
Get-ChildItem $pubDir | ForEach-Object { Write-Host " $($_.Name)" -ForegroundColor Gray }
}
exit 1
}
$exeSizeBytes = (Get-Item $exe).Length
$exeSizeMB = [math]::Round($exeSizeBytes / 1MB, 1)
Write-Ok "DevOpsToolsInstaller.exe ($exeSizeMB MB)"
$copiedCatalog = Join-Path $pubDir 'Assets\catalog.json'
if (Test-Path $copiedCatalog) {
Write-Ok "catalog.json embedded in output"
} else {
Write-Warn "catalog.json not in output - app will fetch from GitHub at runtime"
}
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "+------------------------------------------------------------------+" -ForegroundColor Green
Write-Host "| BUILD SUCCEEDED! |" -ForegroundColor Green
Write-Host "+------------------------------------------------------------------+" -ForegroundColor Green
Write-Host ""
Write-Host " Exe : $exe" -ForegroundColor White
Write-Host " Size : $exeSizeMB MB" -ForegroundColor Gray
Write-Host ""
Write-Host " Run:" -ForegroundColor Yellow
Write-Host " $exe" -ForegroundColor White
Write-Host ""
# ---------------------------------------------------------------------------
# MSIX Package for Microsoft Store
# ---------------------------------------------------------------------------
if ($Msix) {
Write-Step "Building MSIX package for Microsoft Store submission..."
$msixOutDir = Join-Path (Split-Path -Parent $project) 'bin\MsixPackage'
if (-not (Test-Path $msixOutDir)) { New-Item -ItemType Directory -Path $msixOutDir | Out-Null }
$msixArgs = @(
'publish', $project,
'-c', $Configuration,
'-r', 'win-x64',
'--self-contained', 'true',
'-p:Platform=x64',
'-p:BuildMsix=true',
'-p:WindowsAppSDKSelfContained=true',
'-p:AppxPackageSigningEnabled=false',
'-p:GenerateAppxPackageOnBuild=true',
'-p:AppxBundle=Always',
'-p:AppxBundlePlatforms=x64',
"-p:AppxPackageDir=$msixOutDir\"
)
Write-Host " Running dotnet publish with MSIX tooling..." -ForegroundColor Gray
$msixOut = & $dotnet @msixArgs 2>&1
$msixOut | ForEach-Object {
$line = "$_"
if ($line -match ' error ') { Write-Host " $line" -ForegroundColor Red }
elseif ($line -match ' warning ') { Write-Host " $line" -ForegroundColor Yellow }
}
if ($LASTEXITCODE -eq 0) {
# Find the produced .msixupload, .msixbundle, or .msix file
$msixFile = Get-ChildItem -Path $msixOutDir -Include '*.msixupload','*.msixbundle','*.msix' -Recurse |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($msixFile) {
$sizeMB = [math]::Round($msixFile.Length / 1MB, 1)
Write-Ok "MSIX package: $($msixFile.FullName) ($sizeMB MB)"
Write-Host ""
Write-Host " Next step: upload '$($msixFile.Name)' to Microsoft Partner Center" -ForegroundColor Yellow
Write-Host " Dashboard: https://partner.microsoft.com/dashboard" -ForegroundColor Cyan
} else {
Write-Warn "Build succeeded but no .msixupload/.msix file found in $msixOutDir"
Write-Host " Contents:" -ForegroundColor Gray
Get-ChildItem -Recurse $msixOutDir | ForEach-Object { Write-Host " $($_.FullName)" -ForegroundColor Gray }
}
} else {
Write-Err "MSIX build failed - see output above."
}
}
# ---------------------------------------------------------------------------
# Setup Wizard (Inno Setup)
# ---------------------------------------------------------------------------
if ($Setup) {
Write-Step "Building Windows Setup Wizard (Inno Setup)..."
$iscc = Find-ISCC
if (-not $iscc) {
Write-Err "Inno Setup Compiler (ISCC.exe) not found. Install it with: winget install JRSoftware.InnoSetup --scope user"
} else {
$issFile = Join-Path $root 'installer\setup.iss'
$distDir = Join-Path $root 'dist'
if (-not (Test-Path $distDir)) { New-Item -ItemType Directory -Path $distDir | Out-Null }
Write-Host " Compiling with $iscc..." -ForegroundColor Gray
& $iscc "/DSourceDir=$pubDir" $issFile
if ($LASTEXITCODE -eq 0) {
$setupExe = Get-ChildItem -Path $distDir -Filter "*Setup.exe" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($setupExe) {
Write-Ok "Setup Wizard generated: $($setupExe.FullName) ($([math]::Round($setupExe.Length / 1MB, 1)) MB)"
}
} else {
Write-Err "Setup compiler failed with exit code $LASTEXITCODE"
}
}
}
# ---------------------------------------------------------------------------
# Windows Installer (.msi via WiX Toolset)
# ---------------------------------------------------------------------------
if ($Msi) {
Write-Step "Building Windows Installer Package (.msi via WiX Toolset)..."
$wix = Find-WiX
if (-not $wix) {
Write-Err "WiX Toolset (wix.exe) not found."
Write-Host " Install WiX with: dotnet tool install --global wix --version 5.0.2" -ForegroundColor Yellow
Write-Host " And install UI extension: wix extension add -g WixToolset.UI.wixext/5.0.2" -ForegroundColor Yellow
} else {
$wxsFile = Join-Path $root 'installer\setup.wxs'
$distDir = Join-Path $root 'dist'
if (-not (Test-Path $distDir)) { New-Item -ItemType Directory -Path $distDir | Out-Null }
$version = "3.0.1"
if (Test-Path $project) {
$csprojXml = [xml](Get-Content $project)
$verNode = $csprojXml.SelectSingleNode("//Version")
if ($verNode -and $verNode.InnerText) { $version = $verNode.InnerText.Trim() }
}
$assetsDir = Join-Path $root 'src\DevOpsToolsInstaller\Assets'
$outputMsi = Join-Path $distDir "DevOpsToolsInstaller_v${version}_x64.msi"
Write-Host " Compiling with WiX Toolset ($outputMsi)..." -ForegroundColor Gray
& $wix build $wxsFile -ext WixToolset.UI.wixext -arch x64 -d "SourceDir=$pubDir" -d "AssetsDir=$assetsDir" -d "AppVersion=$version" -o $outputMsi
if ($LASTEXITCODE -eq 0 -and (Test-Path $outputMsi)) {
$msiItem = Get-Item $outputMsi
$sizeMB = [math]::Round($msiItem.Length / 1MB, 1)
Write-Ok "Windows Installer (.msi) generated: $($msiItem.FullName) ($sizeMB MB)"
} else {
Write-Err "WiX compiler failed with exit code $LASTEXITCODE"
}
}
}
# ---------------------------------------------------------------------------
# Auto-launch
# ---------------------------------------------------------------------------
if ($Run) {
Write-Step "Launching..."
try {
Start-Process -FilePath $exe
Write-Ok "Launched - check your taskbar"
} catch {
Write-Err "Failed to launch: $_"
}
}