diff --git a/.gitignore b/.gitignore index 1f76942..1dd3530 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,10 @@ artifacts/ *.user *.suo +# 安装包产物(installer/build.ps1 生成) +desktop/installer/out/ +*.wixpdb + # ---------- 运行期 / 日志 ---------- # backend 的 logs/、多实例自测时的 logs-test/、脚本产出的 run/ logs/ diff --git a/desktop/README.md b/desktop/README.md index 0cbeba2..d977f74 100644 --- a/desktop/README.md +++ b/desktop/README.md @@ -113,6 +113,43 @@ dotnet publish -c Release -r win-x64 --self-contained true ` 开发阶段想让 `bin\Debug` 的 exe 也能直接双击,两个办法:装官方 SDK/Desktop Runtime 到标准位置, 或者每次用发布产物验证唤起。 +## 打安装包(MSI) + +`desktop/installer/` 下是安装包定义(**WiX 5**,免费;WiX v6+ 需要 OSMF 付费协议,别装最新版)。 + +```powershell +# 工具只需装一次 +dotnet tool install --global wix --version 5.0.2 + +cd desktop\installer +.\build.ps1 -ServerBaseUrl https://正式域名 +# → out\YuncangTraceSetup-<版本>.msi(约 54 MB,cab 压缩) +``` + +`build.ps1` 做两件事:先 `dotnet publish`(自包含单文件,不依赖运行时)→ 再 `wix build`。 +版本号取自 csproj 的 ``,改版本只改那一处。 + +安装包行为: + +| 项 | 说明 | +| --- | --- | +| 安装范围 | **perUser**(免管理员、无 UAC),装到 `%LOCALAPPDATA%\Programs\YuncangTrace` | +| 启动协议 | **安装即注册** `yuncang://`(HKCU),不需要先启动软件 | +| 卸载 | MSI 自动删除 exe、协议注册、开始菜单 —— 即「取消注册」 | +| 升级 | `MajorUpgrade`:装新版会替换旧版;降级被拦 | +| 用户数据 | `%LOCALAPPDATA%\YuncangTrace\{settings,session}.json` 卸载**不删**(重装后仍保持设置/登录) | + +```powershell +msiexec /i out\YuncangTraceSetup-1.0.0.msi # 安装 +msiexec /x out\YuncangTraceSetup-1.0.0.msi # 卸载 +``` + +> 需要「本机所有用户都能用」时:`Product.wxs` 里 `Scope` 改 `perMachine`、注册表根改 `HKLM`, +> 安装时会要管理员权限(UAC)。默认的 perUser 更省事,也够用(软件数据本来就是按用户存的)。 + +> ⚠️ `build.ps1` 必须保存为 **UTF-8 with BOM**:PowerShell 5.1 读无 BOM 的脚本会按 GBK 解析, +> 中文注释直接把语法搞崩。 + ## 本机接口(前端 `/local` 页用的就是这两个) 服务固定监听 `http://localhost:17300`(端口写在前端页面与插件里)。 diff --git a/desktop/installer/Product.wxs b/desktop/installer/Product.wxs new file mode 100644 index 0000000..503954c --- /dev/null +++ b/desktop/installer/Product.wxs @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/desktop/installer/build.ps1 b/desktop/installer/build.ps1 new file mode 100644 index 0000000..8e24ca2 --- /dev/null +++ b/desktop/installer/build.ps1 @@ -0,0 +1,89 @@ +#requires -Version 5.1 +<# +.SYNOPSIS + 打「云仓视频溯源软件」的 MSI 安装包。 + +.DESCRIPTION + 1. 自包含单文件发布 → desktop\publish\YuncangTrace.LocalService.exe + 2. 用 WiX 5 打包 → desktop\installer\out\YuncangTraceSetup-<版本>.msi + + 安装包特性: + - perUser 安装(免管理员、无 UAC),装到 %LOCALAPPDATA%\Programs\YuncangTrace + - **安装即注册** yuncang:// 协议(HKCU),不需要先启动软件 + - 卸载时 MSI 自动删除协议与开始菜单(= 取消注册) + +.PARAMETER ServerBaseUrl + 打进 exe 的生产后端地址(登录用)。默认是占位地址,正式发布必须传真实域名。 + +.PARAMETER Configuration + 默认 Release。 + +.EXAMPLE + .\build.ps1 -ServerBaseUrl https://trace.example.com + +.NOTES + 前置:dotnet tool install --global wix --version 5.0.2 + (WiX v6+ 需要 OSMF 付费协议,v5 不需要) +#> +param( + [string]$ServerBaseUrl = 'https://packs.example.com', + [string]$Configuration = 'Release' +) + +$ErrorActionPreference = 'Stop' + +$desktop = Split-Path -Parent $PSScriptRoot # desktop\ +$project = Join-Path $desktop 'YuncangTrace.LocalService.csproj' +$publishDir = Join-Path $desktop 'publish' +$outDir = Join-Path $PSScriptRoot 'out' + +# 版本号以 csproj 为准(只读文件,不改它) +$projXml = [xml][System.IO.File]::ReadAllText($project, (New-Object System.Text.UTF8Encoding($false))) +$version = ($projXml.Project.PropertyGroup.Version | Where-Object { $_ } | Select-Object -First 1) +if (-not $version) { throw "csproj 里没找到 " } + +Write-Host "版本:$version" +Write-Host "后端:$ServerBaseUrl" + +# 1) 发布(自包含单文件:双击/协议唤起都不依赖 .NET 运行时) +Push-Location $desktop +try { + dotnet publish $project -c $Configuration -r win-x64 ` + --self-contained true ` + -p:PublishSingleFile=true ` + -p:IncludeNativeLibrariesForSelfExtract=true ` + -p:ServerBaseUrl=$ServerBaseUrl ` + -o $publishDir + if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败($LASTEXITCODE)" } +} +finally { + Pop-Location +} + +$exe = Join-Path $publishDir 'YuncangTrace.LocalService.exe' +if (-not (Test-Path $exe)) { throw "发布产物不存在:$exe" } + +# 2) 打 MSI +$wix = (Get-Command wix.exe -ErrorAction SilentlyContinue).Source +if (-not $wix) { $wix = Join-Path $env:USERPROFILE '.dotnet\tools\wix.exe' } +if (-not (Test-Path $wix)) { + throw "找不到 wix.exe。先执行:dotnet tool install --global wix --version 5.0.2" +} + +New-Item -ItemType Directory -Force -Path $outDir | Out-Null +$msi = Join-Path $outDir "YuncangTraceSetup-$version.msi" + +Push-Location $PSScriptRoot +try { + & $wix build Product.wxs -arch x64 -d "Version=$version" -o $msi + if ($LASTEXITCODE -ne 0) { throw "wix build 失败($LASTEXITCODE)" } +} +finally { + Pop-Location +} + +$size = [math]::Round((Get-Item $msi).Length / 1MB, 1) +Write-Host "" +Write-Host "完成:$msi($size MB)" -ForegroundColor Green +Write-Host "安装(免管理员):msiexec /i `"$msi`"" +Write-Host "卸载: msiexec /x `"$msi`""