Repository navigation
Expand file tree
/
Copy pathbuild-setup.ps1
More file actions
121 lines (97 loc) · 3.95 KB
/
Copy pathbuild-setup.ps1
File metadata and controls
121 lines (97 loc) · 3.95 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
# 打出与 GitHub Release 相同形态的 Velopack 安装包(Setup.exe + 便携 zip)。
# 对齐 .github/workflows/release.yml 的 publish / vpk pack 参数。
# 在仓库根目录执行。首次若无法跑脚本:
# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
#
# 示例:
# .\build-setup.ps1
# .\build-setup.ps1 -Architecture arm64
# .\build-setup.ps1 -Version 0.0.1-local -Clean
#
# 注意:packId 与正式版同为 Moonward,安装会占用同一应用身份。
# 本地包请用带 -local 的版本号,避免和 GitHub 已装版本搅在一起。
param(
[ValidateSet("x64", "arm64", "all")]
[string] $Architecture = "x64",
[string] $Version = "",
[ValidateSet("Debug", "Release")]
[string] $Configuration = "Release",
[string] $Output = "build/setup",
[switch] $Clean,
[switch] $OpenOutput
)
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $false
$RepoRoot = $PSScriptRoot
Set-Location $RepoRoot
if ([string]::IsNullOrWhiteSpace($Version)) {
$sha = (git rev-parse --short HEAD 2>$null)
if ([string]::IsNullOrWhiteSpace($sha)) { $sha = "dev" }
$Version = "0.0.1-local.$sha"
}
function Ensure-Vpk {
if (Get-Command vpk -ErrorAction SilentlyContinue) {
return
}
Write-Host "未找到 vpk,正在安装 Velopack CLI..." -ForegroundColor Yellow
dotnet tool install -g vpk
if ($LASTEXITCODE -ne 0) {
throw "安装 vpk 失败。请手动执行: dotnet tool install -g vpk"
}
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine")
if (-not (Get-Command vpk -ErrorAction SilentlyContinue)) {
throw "vpk 已安装但当前会话找不到命令,请重新打开终端后再试。"
}
}
if ($Clean -and (Test-Path $Output)) {
Write-Host "清理输出目录: $Output" -ForegroundColor Yellow
Remove-Item $Output -Recurse -Force
}
$architectures = if ($Architecture -eq "all") { @("x64", "arm64") } else { @($Architecture) }
$setupArtifacts = @()
Ensure-Vpk
foreach ($arch in $architectures) {
$channel = "win-$arch"
$pubDir = Join-Path $Output "publish/$arch"
$releaseDir = Join-Path $Output "releases/$arch"
Write-Host ""
Write-Host "== Publish $channel ($Configuration, $Version) ==" -ForegroundColor Cyan
New-Item -ItemType Directory -Path $pubDir -Force | Out-Null
dotnet publish src/Starward/Starward.csproj `
-c $Configuration `
-r $channel `
-p:Platform=$arch `
-p:Version=$Version `
-o $pubDir
if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败: $arch" }
Copy-Item -LiteralPath (Join-Path $RepoRoot "LICENSE") -Destination (Join-Path $pubDir "LICENSE") -Force
Write-Host "== Pack Setup $channel ==" -ForegroundColor Cyan
New-Item -ItemType Directory -Path $releaseDir -Force | Out-Null
vpk pack `
--packId Moonward `
--packVersion $Version `
--packDir $pubDir `
--mainExe Moonward.exe `
--packTitle Moonward `
--packAuthors "Scighost,TurmoilZoom" `
--icon src/logo.ico `
--instLicense (Join-Path $pubDir "LICENSE") `
--channel $channel `
--outputDir $releaseDir `
--delta None
if ($LASTEXITCODE -ne 0) { throw "vpk pack 失败: $arch" }
$setup = Get-ChildItem -Path $releaseDir -Filter "*-Setup.exe" | Select-Object -First 1
if ($null -eq $setup) {
throw "未在 $releaseDir 找到 Setup.exe"
}
$setupArtifacts += $setup.FullName
Write-Host "安装包已生成: $($setup.FullName)" -ForegroundColor Green
}
Write-Host ""
Write-Host "全部完成。版本: $Version,配置: $Configuration" -ForegroundColor Green
foreach ($artifact in $setupArtifacts) {
Write-Host " $artifact"
}
if ($OpenOutput -and $setupArtifacts.Count -gt 0) {
Start-Process explorer.exe -ArgumentList "/select,`"$($setupArtifacts[0])`""
}