param( [string]$Version = '0.2.5', [string]$PublishedAt = '', [string]$DotnetPath = '', [string]$IsccPath = '' ) $ErrorActionPreference = 'Stop' $scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $repoRoot = Split-Path -Parent $scriptRoot if ([string]::IsNullOrWhiteSpace($DotnetPath)) { $DotnetPath = Join-Path $repoRoot '.dotnet8\dotnet.exe' } if (-not (Test-Path $DotnetPath)) { throw "未找到 .NET 8 可执行文件:$DotnetPath" } if ([string]::IsNullOrWhiteSpace($IsccPath)) { $candidatePaths = @( 'C:\Users\54972\AppData\Local\Programs\Inno Setup 6\ISCC.exe', 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe', 'C:\Program Files\Inno Setup 6\ISCC.exe' ) $IsccPath = $candidatePaths | Where-Object { Test-Path $_ } | Select-Object -First 1 } if (-not $IsccPath -or -not (Test-Path $IsccPath)) { throw '未找到 Inno Setup 编译器 ISCC.exe' } if ([string]::IsNullOrWhiteSpace($PublishedAt)) { $PublishedAt = (Get-Date).ToString('yyyy-MM-ddTHH:mm:sszzz') } $publishDir = Join-Path $scriptRoot 'dist\publish\win-x64' $installerDir = Join-Path $scriptRoot 'dist\installer' $releaseDir = Join-Path $repoRoot "downloads\print-agent\releases\$Version" $latestDir = Join-Path $repoRoot 'downloads\print-agent\latest' $projectFile = Join-Path $scriptRoot 'FixedAssetPrintAgent\FixedAssetPrintAgent.csproj' $installerScript = Join-Path $scriptRoot 'installer\FixedAssetPrintAgent.iss' New-Item -ItemType Directory -Force -Path $publishDir, $installerDir, $releaseDir, $latestDir | Out-Null Remove-Item -Path (Join-Path $publishDir '*') -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path (Join-Path $installerDir '*') -Recurse -Force -ErrorAction SilentlyContinue & $DotnetPath restore ` $projectFile ` -r win-x64 & $DotnetPath publish ` $projectFile ` -c Release ` -r win-x64 ` --self-contained true ` -p:PublishSingleFile=true ` -p:EnableCompressionInSingleFile=true ` -o $publishDir & $IsccPath "/DMyAppVersion=$Version" $installerScript $installerSource = Join-Path $installerDir "print-agent-setup-$Version.exe" if (-not (Test-Path $installerSource)) { throw "未生成安装包:$installerSource" } $versionedInstaller = Join-Path $releaseDir "print-agent-setup-$Version.exe" $latestInstaller = Join-Path $latestDir 'print-agent-setup.exe' Copy-Item -Force $installerSource $versionedInstaller Copy-Item -Force $installerSource $latestInstaller $releaseManifest = [ordered]@{ version = $Version published_at = $PublishedAt filename = "print-agent-setup-$Version.exe" notes = "打印助手 v$Version,已切回安装即用的大包中文安装器,内置 .NET 8 运行时,行政电脑无需额外安装运行环境;远程打印继续直出网页成品标签图。" source_type = 'server_release' relative_path = "downloads/print-agent/releases/$Version/print-agent-setup-$Version.exe" relativePath = "downloads/print-agent/releases/$Version/print-agent-setup-$Version.exe" } | ConvertTo-Json -Depth 5 $latestManifest = [ordered]@{ version = $Version published_at = $PublishedAt filename = 'print-agent-setup.exe' notes = '打印助手最新稳定版,当前为安装即用的大包中文安装器,内置 .NET 8 运行时,行政电脑无需额外安装运行环境;远程打印继续直出网页成品标签图。' source_type = 'server_release' relative_path = 'downloads/print-agent/latest/print-agent-setup.exe' relativePath = 'downloads/print-agent/latest/print-agent-setup.exe' } | ConvertTo-Json -Depth 5 $utf8NoBom = New-Object System.Text.UTF8Encoding($false) [System.IO.File]::WriteAllText((Join-Path $releaseDir 'manifest.json'), $releaseManifest, $utf8NoBom) [System.IO.File]::WriteAllText((Join-Path $latestDir 'manifest.json'), $latestManifest, $utf8NoBom) $installerSizeMB = [Math]::Round((Get-Item $installerSource).Length / 1MB, 2) Write-Host "安装包已生成:$installerSource ($installerSizeMB MB)" Write-Host "已同步到:$releaseDir" Write-Host "已更新 latest 清单和下载包。"