#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`""