Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
753 lines (643 loc) · 28.2 KB
/
Copy pathbuild.ps1
File metadata and controls
753 lines (643 loc) · 28.2 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
<#
.SYNOPSIS
Build script for OpenClaw Windows Hub
.DESCRIPTION
Builds all projects, checks prerequisites, and provides clear guidance.
.PARAMETER Project
Which project to build: All, Tray, WinUI, Shared, Cli, WinNodeCli, SetupEngine
Default: All
.PARAMETER Configuration
Build configuration: Debug, Release
Default: Debug
.PARAMETER CheckOnly
Only check prerequisites, don't build
.PARAMETER DevBuild
Build the WinUI app with the side-by-side dev identity. Defaults off so
release identity remains the default for every configuration.
.PARAMETER Msix
Produce an MSIX package. The two modes are mutually exclusive because they
build different applications, not two flavors of one:
Dev - locally signed, self-contained package using the side-by-side dev
identity. Implies -DevBuild and uses the certificate created by
scripts\setup-dev-msix-cert.ps1. The manifest revision is the
installed development package revision plus one, so repeated
Add-AppxPackage sideloads upgrade cleanly.
Store - unsigned, self-contained packages for x64 and ARM64 using the
release identity. Partner Center signs them, so no local
certificate is used, and the manifest revision is pinned to 0
because the Store reserves that field. Forces -Configuration
Release and cannot be combined with -DevBuild.
.PARAMETER NoTrustRepository
Do not automatically add this checkout to git safe.directory when GitVersion
cannot read a repo owned by a different Windows account/group. The script
will print the manual command instead.
.PARAMETER MsixRevision
Explicit Dev package revision (1-65535), for example a CI workflow run
number. Omit for the existing installed-revision-plus-one behavior.
Only valid with -Msix Dev.
.PARAMETER MsixOutputDirectory
Empty directory for Dev packaging output. Relative paths resolve against
the repository root. The directory is never cleared automatically.
Only valid with -Msix Dev; omission preserves the local AppPackages path.
.PARAMETER MsixBaseVersion
Explicit three-part package base from the CI MSIX allocator. Only valid
with -Msix Dev. Does not override the application's GitVersion or assembly
metadata. When omitted, a local build reuses an installed Dev package's
higher three-part base so Windows accepts the build as an upgrade.
.EXAMPLE
.\build.ps1
.\build.ps1 -Project WinUI -Configuration Release
.\build.ps1 -CheckOnly
.\build.ps1 -Project WinUI -Msix Dev
.\build.ps1 -Project WinUI -Msix Store
#>
# CmdletBinding makes unrecognized parameters a hard error. Without it a removed
# or misspelled switch such as -PackageMsix lands in $args and is silently
# ignored, producing an unpackaged build with no indication anything was wrong.
[CmdletBinding()]
param(
[ValidateSet("All", "Tray", "WinUI", "Shared", "Cli", "WinNodeCli", "SetupEngine")]
[string]$Project = "All",
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",
[switch]$CheckOnly,
[switch]$DevBuild,
[ValidateSet("Dev", "Store")]
[string]$Msix,
[ValidateRange(1, 65535)]
[int]$MsixRevision,
[ValidateNotNullOrEmpty()]
[string]$MsixOutputDirectory,
[ValidatePattern('^[1-9]\d*\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$')]
[ValidateScript({
foreach ($part in $_.Split('.')) {
[uint16]$value = 0
if (-not [uint16]::TryParse($part, [ref]$value)) { return $false }
}
return $true
})]
[string]$MsixBaseVersion,
[switch]$NoTrustRepository
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $repoRoot
$buildDevMsix = ($Msix -eq "Dev")
$buildStoreMsix = ($Msix -eq "Store")
if (($PSBoundParameters.ContainsKey("MsixRevision") -or
$PSBoundParameters.ContainsKey("MsixOutputDirectory")) -and -not $buildDevMsix) {
throw "-MsixRevision and -MsixOutputDirectory require -Msix Dev."
}
$explicitMsixRevision = $PSBoundParameters.ContainsKey("MsixRevision")
if ($PSBoundParameters.ContainsKey("MsixBaseVersion") -and -not $buildDevMsix) {
throw "-MsixBaseVersion requires -Msix Dev."
}
if ($MsixOutputDirectory) {
$MsixOutputDirectory = [IO.Path]::GetFullPath([IO.Path]::Combine($repoRoot, $MsixOutputDirectory))
if ((Test-Path -LiteralPath $MsixOutputDirectory) -and
(-not (Test-Path -LiteralPath $MsixOutputDirectory -PathType Container) -or
@(Get-ChildItem -LiteralPath $MsixOutputDirectory -Force).Count -gt 0)) {
throw "The Dev MSIX output directory must be absent or empty: $MsixOutputDirectory"
}
}
if ($buildDevMsix) {
$DevBuild = $true
}
# Microsoft Store packages ship the release identity and are signed by Partner
# Center, so they are incompatible with the dev identity and the local dev cert.
$storeMsixRuntimeIdentifiers = @("win-x64", "win-arm64")
if ($buildStoreMsix) {
if ($DevBuild) {
throw "-Msix Store cannot be combined with -DevBuild. Store packages must use the release identity."
}
if ($PSBoundParameters.ContainsKey("Configuration") -and $Configuration -ne "Release") {
throw "-Msix Store requires -Configuration Release. Debug binaries are not accepted by Store certification."
}
$Configuration = "Release"
}
# Colors for output
function Write-Header($text) { Write-Host "`n=== $text ===" -ForegroundColor Cyan }
function Write-Success($text) { Write-Host "✅ $text" -ForegroundColor Green }
function Write-Warning($text) { Write-Host "⚠️ $text" -ForegroundColor Yellow }
function Write-Error($text) { Write-Host "❌ $text" -ForegroundColor Red }
function Write-Info($text) { Write-Host " $text" -ForegroundColor Gray }
# Track issues
$issues = @()
function Test-WindowsHost {
$isWindowsVariable = Get-Variable -Name IsWindows -ErrorAction SilentlyContinue
if ($isWindowsVariable) {
return [bool]$isWindowsVariable.Value
}
return [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT
}
function ConvertTo-GitSafeDirectoryPath($path) {
return ([System.IO.Path]::GetFullPath($path).TrimEnd("\") -replace "\\", "/")
}
function Test-GitSafeDirectoryContains($path) {
$expected = (ConvertTo-GitSafeDirectoryPath $path).ToLowerInvariant()
$safeDirectories = & git config --global --get-all safe.directory 2>$null
if ($LASTEXITCODE -ne 0 -or -not $safeDirectories) {
return $false
}
foreach ($safeDirectory in $safeDirectories) {
if ($safeDirectory -eq "*") {
return $true
}
$normalized = ($safeDirectory.Trim().TrimEnd("\", "/") -replace "\\", "/").ToLowerInvariant()
if ($normalized -eq $expected) {
return $true
}
}
return $false
}
function Get-SecurityIdentifierValue($accountName) {
try {
return ([System.Security.Principal.NTAccount]$accountName).
Translate([System.Security.Principal.SecurityIdentifier]).
Value
} catch {
return $null
}
}
function Ensure-GitVersionRepositoryTrust {
if (-not (Test-Path (Join-Path $repoRoot ".git"))) {
return
}
$owner = (Get-Acl -LiteralPath $repoRoot).Owner
$currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$ownerSid = Get-SecurityIdentifierValue $owner
if ($ownerSid -and $ownerSid -eq $currentIdentity.User.Value) {
return
}
if (Test-GitSafeDirectoryContains $repoRoot) {
return
}
$safeDirectory = ConvertTo-GitSafeDirectoryPath $repoRoot
Write-Warning "Repository owner is '$owner' but the current user is '$($currentIdentity.Name)'. GitVersion/LibGit2Sharp may reject this checkout unless it is trusted."
if ($NoTrustRepository -or $CheckOnly) {
Write-Info "Run this once, then retry:"
Write-Info "git config --global --add safe.directory `"$safeDirectory`""
$script:issues += "Repository is not trusted for GitVersion"
return
}
Write-Info "Adding git safe.directory entry: $safeDirectory"
& git config --global --add safe.directory $safeDirectory
if ($LASTEXITCODE -ne 0) {
Write-Error "Unable to add git safe.directory entry."
Write-Info "Run this once, then retry the build:"
Write-Info "git config --global --add safe.directory `"$safeDirectory`""
$script:issues += "Repository is not trusted for GitVersion"
return
}
Write-Success "Repository trusted for GitVersion"
}
function Ensure-GitVersionRepositoryHistory {
$insideWorkTree = & git -C $repoRoot rev-parse --is-inside-work-tree 2>$null
if ($LASTEXITCODE -ne 0 -or $insideWorkTree -ne "true") {
Write-Error "Git metadata not found. GitVersion requires a git clone with full history."
Write-Info "Clone the repository with git, then rerun .\build.ps1."
$script:issues += "Repository is missing git metadata required by GitVersion"
return
}
$isShallow = & git -C $repoRoot rev-parse --is-shallow-repository 2>$null
if ($LASTEXITCODE -eq 0 -and $isShallow -eq "true") {
Write-Error "Repository is a shallow clone. GitVersion requires full git history."
Write-Info "Run this once, then retry the build:"
Write-Info "git fetch --unshallow --tags origin"
$script:issues += "Repository is shallow; GitVersion requires full history"
}
}
Write-Host @"
🦞 OpenClaw Windows Hub - Build Script
=======================================
"@ -ForegroundColor Magenta
# =============================================================================
# PREREQUISITE CHECKS
# =============================================================================
Write-Header "Checking Prerequisites"
# Check OS
if (-not (Test-WindowsHost)) {
Write-Error "This project requires Windows"
exit 1
}
Write-Success "Windows detected"
# Check .NET SDK
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
if (-not $dotnet) {
Write-Error ".NET SDK not found"
Write-Info "Download from: https://dotnet.microsoft.com/download"
$issues += "Missing .NET SDK"
} else {
# Reactor preview.14 source generators require Roslyn 5.9, first shipped
# in the .NET 10.0.400 feature band.
$minimumNet10Sdk = [version]"10.0.400"
$sdks = & dotnet --list-sdks 2>$null
$hasNet10 = $sdks |
ForEach-Object {
$match = [regex]::Match($_, "^(\d+\.\d+\.\d+)")
if ($match.Success) { [version]$match.Groups[1].Value }
} |
Where-Object { $_.Major -eq 10 -and $_ -ge $minimumNet10Sdk }
if (-not $hasNet10) {
Write-Error ".NET SDK 10.0.400 or newer not found (required for all projects)"
Write-Info "Download from: https://dotnet.microsoft.com/download/dotnet/10.0"
$issues += "Missing .NET SDK 10.0.400 or newer"
} else {
$dotnetVersion = & dotnet --version 2>$null
if ($LASTEXITCODE -eq 0 -and $dotnetVersion) {
Write-Success ".NET SDK: $dotnetVersion"
}
Write-Success ".NET SDK 10.0.400 or newer available"
}
}
# Check Git (GitVersion reads repository metadata during .NET builds)
$git = Get-Command git -ErrorAction SilentlyContinue
if (-not $git) {
Write-Error "Git not found (required by GitVersion during builds)"
Write-Info "Install via: winget install Git.Git"
Write-Info "Or download from: https://git-scm.com/download/win"
$issues += "Missing Git"
} else {
$gitVersion = & git --version 2>$null
if ($LASTEXITCODE -eq 0 -and $gitVersion) {
Write-Success "$gitVersion"
} else {
Write-Success "Git detected"
}
Ensure-GitVersionRepositoryTrust
Ensure-GitVersionRepositoryHistory
}
# Check Windows SDK (for WinUI)
$windowsSdkPath = "${env:ProgramFiles(x86)}\Windows Kits\10\Include"
if (Test-Path $windowsSdkPath) {
$sdkVersions = @(
Get-ChildItem $windowsSdkPath -Directory |
Where-Object { $_.Name -match "^\d+\.\d+\.\d+\.\d+$" } |
Sort-Object { [version]$_.Name } -Descending |
Select-Object -ExpandProperty Name
)
if ($sdkVersions.Count -gt 0) {
Write-Success "Windows SDK: $($sdkVersions[0])"
} else {
Write-Warning "Windows 10 SDK not found (needed for WinUI build)"
Write-Info "Install via Visual Studio Installer, standalone SDK, or: winget install --id Microsoft.WindowsSDK.10.0.26100 -e"
$issues += "Windows 10 SDK not detected"
}
} else {
Write-Warning "Windows 10 SDK not found (needed for WinUI build)"
Write-Info "Install via Visual Studio Installer, standalone SDK, or: winget install --id Microsoft.WindowsSDK.10.0.26100 -e"
$issues += "Windows 10 SDK not detected"
}
# Check WebView2 Runtime (for WinUI chat window)
$webView2Key = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
$webView2KeyAlt = "HKCU:\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"
$webView2Version = $null
if (Test-Path $webView2Key) {
$webView2Version = (Get-ItemProperty $webView2Key -ErrorAction SilentlyContinue).pv
} elseif (Test-Path $webView2KeyAlt) {
$webView2Version = (Get-ItemProperty $webView2KeyAlt -ErrorAction SilentlyContinue).pv
}
if ($webView2Version) {
Write-Success "WebView2 Runtime: $webView2Version"
} else {
Write-Warning "WebView2 Runtime not detected (needed for WinUI chat window)"
Write-Info "Usually pre-installed on Windows 10/11. Get from: https://developer.microsoft.com/microsoft-edge/webview2"
# Not a hard failure - app will fall back to browser
}
# Check architecture
$arch = $env:PROCESSOR_ARCHITECTURE
Write-Success "Architecture: $arch"
if ($arch -eq "ARM64") {
Write-Info "ARM64 detected - builds will target ARM64 by default"
}
# Use the same resolver as the app output. A system-installed redistributable
# cannot repair the older app-local fallback that shadows it in x64 builds.
if ($dotnet -and $hasNet10 -and $arch -ne "ARM64" -and $Project -in @("All", "Tray", "WinUI")) {
& dotnet msbuild (Join-Path $repoRoot "src\Directory.Build.targets") `
-target:ResolveOpenClawVCRuntimeFromVSInstall `
-property:OpenClawVCRuntimeArch=x64 -nologo -verbosity:minimal
if ($LASTEXITCODE -eq 0) {
Write-Success "Compatible app-local Visual C++ runtime detected"
} else {
Write-Error "Compatible app-local Visual C++ runtime not found"
Write-Info "Install or update 'C++ Redistributable Update' (Microsoft.VisualStudio.Component.VC.Redist.14.Latest) in the Visual Studio Installer."
$issues += "Missing compatible Visual Studio C++ Redistributable"
}
}
if ($buildStoreMsix) {
if ($Project -notin @("All", "Tray", "WinUI")) {
Write-Error "-Msix Store requires -Project All, Tray, or WinUI."
$issues += "Store MSIX packaging requires the WinUI project"
}
Write-Success "Store MSIX target architectures: $($storeMsixRuntimeIdentifiers -join ', ')"
Write-Info "Packages are left unsigned; Partner Center signs Store submissions."
}
if ($buildDevMsix) {
if ($Project -notin @("All", "Tray", "WinUI")) {
Write-Error "-Msix Dev requires -Project All, Tray, or WinUI."
$issues += "MSIX packaging requires the WinUI project"
}
$devMsixCertificateDirectory = Join-Path $env:LOCALAPPDATA "OpenClawDevelopment\MSIX"
$devMsixThumbprintFile = Join-Path $devMsixCertificateDirectory "dev-msix-thumbprint.txt"
$devMsixThumbprint = if (Test-Path $devMsixThumbprintFile) {
(Get-Content -LiteralPath $devMsixThumbprintFile -Raw).Trim()
} else {
""
}
$devMsixCertificate = if ($devMsixThumbprint) {
Get-Item "Cert:\CurrentUser\My\$devMsixThumbprint" -ErrorAction SilentlyContinue
} else {
$null
}
if ($devMsixCertificate) {
Write-Success "Development MSIX signing certificate: $($devMsixCertificate.Thumbprint)"
} else {
Write-Error "Development MSIX signing certificate not found."
Write-Info "Run .\scripts\setup-dev-msix-cert.ps1 from an elevated PowerShell, then retry."
$issues += "Missing development MSIX signing certificate"
}
}
# Summary
Write-Header "Prerequisite Summary"
if ($issues.Count -eq 0) {
Write-Success "All prerequisites met!"
} else {
Write-Warning "$($issues.Count) issue(s) found:"
foreach ($issue in $issues) {
Write-Info "- $issue"
}
}
Write-Header "Validating Documentation"
& (Join-Path $repoRoot "scripts\validate-docs.ps1") -RepoRoot $repoRoot
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
if ($issues.Count -gt 0) {
Write-Host "`nFix the prerequisite issue(s) above, then rerun .\build.ps1.`n" -ForegroundColor Yellow
exit 1
}
if ($CheckOnly) {
Write-Host "`nRun without -CheckOnly to build.`n"
exit 0
}
# =============================================================================
# BUILD
# =============================================================================
Write-Header "Building Projects ($Configuration)"
# Detect runtime identifier based on architecture
$rid = switch ($arch) {
"ARM64" { "win-arm64" }
default { "win-x64" }
}
Write-Info "Runtime identifier: $rid"
$buildResults = @{}
function Invoke-DotNetCaptured($arguments) {
$previousErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
return & dotnet @arguments 2>&1
} finally {
$ErrorActionPreference = $previousErrorActionPreference
}
}
function Get-InstalledDevMsixPackage {
Get-AppxPackage -Name "OpenClawFoundation.OpenClaw.Dev" -ErrorAction SilentlyContinue |
Where-Object Publisher -eq "CN=OpenClaw Local Development" |
Sort-Object { [version]$_.Version.ToString() } -Descending |
Select-Object -First 1
}
function Get-CurrentAppBaseVersion {
$version = & (Join-Path $repoRoot "scripts\Get-OpenClawVersion.ps1") -Variable MajorMinorPatch
if ($LASTEXITCODE -ne 0 -or $version -notmatch '^[1-9]\d*\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$') {
throw "Could not resolve the current three-part application version for Dev MSIX packaging."
}
return $version.Trim()
}
function Select-LocalDevMsixBaseVersion($installedPackageVersion, $appBaseVersion) {
if ($null -eq $installedPackageVersion) {
return $null
}
$installed = [version]$installedPackageVersion.ToString()
$installedBase = [version]::new($installed.Major, $installed.Minor, $installed.Build)
$appBase = [version]$appBaseVersion
if ($installedBase -le $appBase) {
return $null
}
return "$($installed.Major).$($installed.Minor).$($installed.Build)"
}
function Build-Project($name, $path, $useRid = $false, $packageMsix = $false) {
Write-Host "`nBuilding $name..." -ForegroundColor White
if (-not (Test-Path $path)) {
Write-Error "Project not found: $path"
return $false
}
if ($packageMsix) {
$installedDevPackage = if (-not $explicitMsixRevision -or -not $MsixBaseVersion) {
Get-InstalledDevMsixPackage
} else {
$null
}
$effectiveMsixBaseVersion = if ($MsixBaseVersion) {
$MsixBaseVersion
} elseif ($installedDevPackage) {
Select-LocalDevMsixBaseVersion `
-installedPackageVersion $installedDevPackage.Version `
-appBaseVersion (Get-CurrentAppBaseVersion)
} else {
$null
}
$msixRevision = if ($explicitMsixRevision) {
$MsixRevision
} else {
if ($installedDevPackage) {
([version]$installedDevPackage.Version.ToString()).Revision + 1
} else {
1
}
}
if ($msixRevision -gt 65535) {
Write-Error "The installed development MSIX revision is already 65535. Remove the installed OpenClawFoundation.OpenClaw.Dev package before rebuilding."
return $false
}
$dotnetArgs = @(
"publish", $path,
"-c", $Configuration,
"-r", $rid,
"--self-contained",
"-p:MsixRevision=$msixRevision"
)
} else {
$dotnetArgs = @("build", $path, "-c", $Configuration)
# WinUI requires runtime identifier for self-contained WebView2 support
if ($useRid) {
$dotnetArgs += @("-r", $rid)
}
}
if ($DevBuild -and ($name -eq "WinUI" -or $name -eq "Tray")) {
$dotnetArgs += "-p:DevBuild=true"
}
if ($packageMsix) {
$platform = if ($rid -eq "win-arm64") { "ARM64" } else { "x64" }
$appxOutput = if ($MsixOutputDirectory) {
$MsixOutputDirectory.TrimEnd('\') + '\'
} else {
"AppPackages\"
}
$dotnetArgs += @(
"-p:Platform=$platform",
"-p:PackageMsix=true",
"-p:GenerateAppxPackageOnBuild=true",
"-p:AppxBundle=Never",
"-p:UapAppxPackageBuildMode=SideloadOnly",
"-p:AppxPackageDir=$appxOutput"
)
if ($effectiveMsixBaseVersion) {
$dotnetArgs += "-p:MsixPackageBaseVersion=$effectiveMsixBaseVersion"
}
}
if ($name -eq "WinUI" -or $name -eq "Tray") {
& (Join-Path $repoRoot "scripts\Initialize-ReactorPackages.ps1")
}
$result = Invoke-DotNetCaptured $dotnetArgs
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
Write-Success "$name built successfully"
return $true
} else {
Write-Error "$name build failed"
# Show relevant error lines
$result | Select-String "error" | Select-Object -First 5 | ForEach-Object {
Write-Info $_.Line
}
$lockingProcesses = $result |
Select-String 'file is locked by: "(.+) \((\d+)\)"' |
ForEach-Object {
[PSCustomObject]@{
Name = $_.Matches[0].Groups[1].Value
Id = $_.Matches[0].Groups[2].Value
}
} |
Sort-Object Id -Unique
foreach ($lockingProcess in $lockingProcesses) {
Write-Warning "Build output is locked by $($lockingProcess.Name) (PID $($lockingProcess.Id)). Close the app, or run: Stop-Process -Id $($lockingProcess.Id)"
}
return $false
}
}
function Get-ProjectTargetFramework($path) {
if (-not (Test-Path $path)) {
return $null
}
[xml]$projectXml = Get-Content $path -Raw
return $projectXml.Project.PropertyGroup |
ForEach-Object { $_.TargetFramework } |
Where-Object { $_ } |
Select-Object -First 1
}
$projects = @{
"Shared" = @{ Path = "src/OpenClaw.Shared/OpenClaw.Shared.csproj"; UseRid = $false }
"Cli" = @{ Path = "src/OpenClaw.Cli/OpenClaw.Cli.csproj"; UseRid = $false }
"WinNodeCli" = @{ Path = "src/OpenClaw.WinNode.Cli/OpenClaw.WinNode.Cli.csproj"; UseRid = $false }
"Tray" = @{ Path = "src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj"; UseRid = $true }
"WinUI" = @{ Path = "src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj"; UseRid = $true }
"SetupEngine" = @{ Path = "src/OpenClaw.SetupEngine/OpenClaw.SetupEngine.csproj"; UseRid = $false }
}
if ($buildStoreMsix) {
# scripts\Build-StoreMsix.ps1 owns packaging, identity verification, and the
# provenance sidecar. build.ps1 only drives it once per architecture.
$storeArchitectures = $storeMsixRuntimeIdentifiers | ForEach-Object { $_ -replace "^win-", "" }
$storePackages = @()
foreach ($storeArchitecture in $storeArchitectures) {
Write-Host "`nBuilding Store MSIX ($storeArchitecture)..." -ForegroundColor White
try {
& (Join-Path $repoRoot "scripts\Build-StoreMsix.ps1") `
-Architecture $storeArchitecture `
-Configuration $Configuration
} catch {
Write-Error "Store MSIX ($storeArchitecture) packaging failed: $($_.Exception.Message)"
exit 1
}
$storePackages += Join-Path $repoRoot "artifacts\msix\$storeArchitecture\OpenClaw-$storeArchitecture.msix"
}
Write-Header "Store MSIX Packages"
foreach ($package in $storePackages) {
if (-not (Test-Path -LiteralPath $package)) {
Write-Error "Expected package was not produced: $package"
exit 1
}
Write-Success $package
}
Write-Host "`nUpload both packages to the same Partner Center submission." -ForegroundColor Cyan
Write-Info "Identity is taken from src\OpenClaw.Tray.WinUI\Package.appxmanifest and must keep"
Write-Info "matching Partner Center > Product management > Product identity. The Store re-signs"
Write-Info "these packages, so they are intentionally left unsigned here."
Write-Host ""
exit 0
}
$toBuild = if ($Project -eq "All") { @("Shared", "Cli", "WinNodeCli", "SetupEngine", "WinUI") } else { @($Project) }
# Always build Shared first if building other projects
if ($Project -ne "Shared" -and $Project -ne "All" -and $toBuild -notcontains "Shared") {
$toBuild = @("Shared") + $toBuild
}
for ($i = 0; $i -lt $toBuild.Count; $i++) {
$proj = $toBuild[$i]
if ($projects.ContainsKey($proj)) {
$projInfo = $projects[$proj]
$shouldPackageMsix = $buildDevMsix -and ($proj -eq "WinUI" -or $proj -eq "Tray")
$buildResults[$proj] = Build-Project $proj $projInfo.Path $projInfo.UseRid $shouldPackageMsix
if ($proj -eq "Shared" -and -not $buildResults[$proj] -and $i -lt ($toBuild.Count - 1)) {
Write-Warning "Skipping remaining projects because Shared failed."
break
}
}
}
Write-Header "Build Summary"
$successCount = ($buildResults.Values | Where-Object { $_ -eq $true }).Count
$failCount = ($buildResults.Values | Where-Object { $_ -eq $false }).Count
foreach ($proj in $buildResults.Keys) {
if ($buildResults[$proj]) {
Write-Success "$proj"
} else {
Write-Error "$proj"
}
}
Write-Host ""
if ($failCount -eq 0) {
Write-Host "🦞 All builds succeeded!" -ForegroundColor Green
Write-Host "`nTo run:" -ForegroundColor Cyan
if (($buildResults.ContainsKey("WinUI") -and $buildResults["WinUI"]) -or ($buildResults.ContainsKey("Tray") -and $buildResults["Tray"])) {
$winUIProjectPath = $projects["WinUI"].Path
$winUITargetFramework = Get-ProjectTargetFramework $winUIProjectPath
$winUIProjectDirectory = (Split-Path -Parent $winUIProjectPath).Replace("/", "\")
if ($buildDevMsix) {
$packageDirectory = if ($MsixOutputDirectory) { $MsixOutputDirectory } else {
Join-Path $repoRoot "$winUIProjectDirectory\AppPackages"
}
$devMsixPackage = Get-ChildItem $packageDirectory -Recurse -Filter "*.msix" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($devMsixPackage) {
Write-Host " MSIX: $($devMsixPackage.FullName)" -ForegroundColor White
Write-Host " Install: Add-AppxPackage -Path `"$($devMsixPackage.FullName)`" -ForceApplicationShutdown" -ForegroundColor White
} else {
Write-Warning "MSIX packaging succeeded but no .msix was found under $packageDirectory."
}
}
if ($winUITargetFramework) {
$winUIOutputDirectory = ".\$winUIProjectDirectory\bin\$Configuration\$winUITargetFramework\$rid"
$winUIManifestPath = ".\$winUIProjectDirectory\Package.appxmanifest"
$runIdentitySwitch = if ($DevBuild) { " -Dev" } else { "" }
Write-Host " WinUI: .\run-app-local.ps1 -NoBuild$runIdentitySwitch" -ForegroundColor White
Write-Host " Isolated: .\run-app-local.ps1 -NoBuild -Isolated$runIdentitySwitch" -ForegroundColor White
Write-Host " Dev: .\run-app-local.ps1 -Dev" -ForegroundColor White
Write-Host " WinApp: .\run-app-local.ps1 -NoBuild -UseWinApp$runIdentitySwitch" -ForegroundColor White
Write-Host " Direct launch is default. -UseWinApp runs: winapp run `"$winUIOutputDirectory`" --manifest `"$winUIManifestPath`" --executable `"OpenClaw.Tray.WinUI.exe`" --debug-output" -ForegroundColor DarkGray
} else {
Write-Warning "Unable to determine WinUI target framework from $winUIProjectPath"
}
}
} else {
Write-Host "❌ $failCount build(s) failed" -ForegroundColor Red
exit 1
}
Write-Host ""