197 lines
6.7 KiB
PowerShell
197 lines
6.7 KiB
PowerShell
|
|
#Requires -Version 5.1
|
|||
|
|
<#
|
|||
|
|
.SYNOPSIS
|
|||
|
|
Better-Seewo 一键构建脚本
|
|||
|
|
.DESCRIPTION
|
|||
|
|
自动还原 NuGet 包、编译 Manager 和 Installer 项目,并打包为发布版本。
|
|||
|
|
支持 Debug / Release 配置,支持框架依赖和自包含两种发布模式。
|
|||
|
|
.PARAMETER Configuration
|
|||
|
|
构建配置:Debug 或 Release(默认 Release)
|
|||
|
|
.PARAMETER SelfContained
|
|||
|
|
是否自包含 .NET Runtime(默认 $false,需要用户安装 .NET 6 Desktop Runtime)
|
|||
|
|
.PARAMETER OutputPath
|
|||
|
|
输出目录(默认 ./Publish)
|
|||
|
|
.EXAMPLE
|
|||
|
|
.\build.ps1
|
|||
|
|
.\build.ps1 -Configuration Release -SelfContained $true
|
|||
|
|
#>
|
|||
|
|
param(
|
|||
|
|
[ValidateSet("Debug", "Release")]
|
|||
|
|
[string]$Configuration = "Release",
|
|||
|
|
|
|||
|
|
[bool]$SelfContained = $false,
|
|||
|
|
|
|||
|
|
[string]$OutputPath = "$PSScriptRoot\Publish"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
$ErrorActionPreference = "Stop"
|
|||
|
|
|
|||
|
|
# ========== 颜色输出辅助函数 ==========
|
|||
|
|
function Write-Info { param([string]$Message) Write-Host "[INFO] $Message" -ForegroundColor Cyan }
|
|||
|
|
function Write-Success { param([string]$Message) Write-Host "[OK] $Message" -ForegroundColor Green }
|
|||
|
|
function Write-Warning { param([string]$Message) Write-Host "[WARN] $Message" -ForegroundColor Yellow }
|
|||
|
|
function Write-Error { param([string]$Message) Write-Host "[ERR] $Message" -ForegroundColor Red }
|
|||
|
|
|
|||
|
|
# ========== 标题 ==========
|
|||
|
|
Write-Host ""
|
|||
|
|
Write-Host "========================================" -ForegroundColor Magenta
|
|||
|
|
Write-Host " Better-Seewo 一键构建脚本 v2.0.1" -ForegroundColor Magenta
|
|||
|
|
Write-Host " 雾生万象,启以为光" -ForegroundColor Magenta
|
|||
|
|
Write-Host "========================================" -ForegroundColor Magenta
|
|||
|
|
Write-Host ""
|
|||
|
|
|
|||
|
|
# ========== 检测 .NET SDK ==========
|
|||
|
|
Write-Info "检测 .NET SDK ..."
|
|||
|
|
$dotnetVersion = dotnet --version 2>$null
|
|||
|
|
if (-not $dotnetVersion) {
|
|||
|
|
Write-Error ".NET SDK 未找到!请先安装 .NET 6.0 SDK:"
|
|||
|
|
Write-Error " https://dotnet.microsoft.com/download/dotnet/6.0"
|
|||
|
|
exit 1
|
|||
|
|
}
|
|||
|
|
Write-Success ".NET SDK 版本: $dotnetVersion"
|
|||
|
|
|
|||
|
|
# ========== 检测解决方案路径 ==========
|
|||
|
|
$SolutionDir = $PSScriptRoot
|
|||
|
|
$SolutionFile = Join-Path $SolutionDir "Better-Seewo.sln"
|
|||
|
|
if (-not (Test-Path $SolutionFile)) {
|
|||
|
|
Write-Error "未找到解决方案文件: $SolutionFile"
|
|||
|
|
exit 1
|
|||
|
|
}
|
|||
|
|
Write-Info "解决方案路径: $SolutionFile"
|
|||
|
|
|
|||
|
|
# ========== 清理旧输出 ==========
|
|||
|
|
Write-Info "清理旧构建输出 ..."
|
|||
|
|
$OutputManager = Join-Path $OutputPath "Manager"
|
|||
|
|
$OutputInstaller = Join-Path $OutputPath "Installer"
|
|||
|
|
if (Test-Path $OutputPath) {
|
|||
|
|
Remove-Item -Recurse -Force $OutputPath
|
|||
|
|
}
|
|||
|
|
New-Item -ItemType Directory -Path $OutputManager -Force | Out-Null
|
|||
|
|
New-Item -ItemType Directory -Path $OutputInstaller -Force | Out-Null
|
|||
|
|
Write-Success "输出目录已清理: $OutputPath"
|
|||
|
|
|
|||
|
|
# ========== 还原 NuGet 包 ==========
|
|||
|
|
Write-Info "还原 NuGet 包 ..."
|
|||
|
|
$restoreArgs = @("restore", $SolutionFile)
|
|||
|
|
# 如果 EasiPlugin 私有源不可用,跳过它
|
|||
|
|
$NugetConfig = Join-Path $SolutionDir "NuGet.config"
|
|||
|
|
if (Test-Path $NugetConfig) {
|
|||
|
|
[xml]$nugetXml = Get-Content $NugetConfig
|
|||
|
|
$easiPluginSource = $nugetXml.configuration.packageSources.add | Where-Object { $_.key -eq "EasiPlugin" }
|
|||
|
|
if ($easiPluginSource) {
|
|||
|
|
Write-Warning "检测到 EasiPlugin 私有 NuGet 源,Better-EN5 项目可能无法编译"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
& dotnet @restoreArgs
|
|||
|
|
if ($LASTEXITCODE -ne 0) {
|
|||
|
|
Write-Warning "NuGet 还原部分失败(EasiPlugin SDK 可能无法访问),继续构建可用项目 ..."
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# ========== 构建 Manager ==========
|
|||
|
|
Write-Info "构建 Manager 项目 [$Configuration] ..."
|
|||
|
|
$managerArgs = @(
|
|||
|
|
"publish",
|
|||
|
|
(Join-Path $SolutionDir "Manager\Manager.csproj"),
|
|||
|
|
"-c", $Configuration,
|
|||
|
|
"--no-restore",
|
|||
|
|
"-o", $OutputManager,
|
|||
|
|
"-p:SolutionDir=$SolutionDir\"
|
|||
|
|
)
|
|||
|
|
if ($SelfContained) {
|
|||
|
|
$managerArgs += "--self-contained"
|
|||
|
|
$managerArgs += "true"
|
|||
|
|
$managerArgs += "-r"
|
|||
|
|
$managerArgs += "win-x64"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
& dotnet @managerArgs
|
|||
|
|
if ($LASTEXITCODE -ne 0) {
|
|||
|
|
Write-Error "Manager 项目构建失败!"
|
|||
|
|
exit 1
|
|||
|
|
}
|
|||
|
|
Write-Success "Manager 构建完成 -> $OutputManager"
|
|||
|
|
|
|||
|
|
# ========== 构建 Installer ==========
|
|||
|
|
Write-Info "构建 Installer 项目 [$Configuration] ..."
|
|||
|
|
$installerArgs = @(
|
|||
|
|
"publish",
|
|||
|
|
(Join-Path $SolutionDir "Installer\Installer.csproj"),
|
|||
|
|
"-c", $Configuration,
|
|||
|
|
"--no-restore",
|
|||
|
|
"-o", $OutputInstaller,
|
|||
|
|
"-p:SolutionDir=$SolutionDir\"
|
|||
|
|
)
|
|||
|
|
if ($SelfContained) {
|
|||
|
|
$installerArgs += "--self-contained"
|
|||
|
|
$installerArgs += "true"
|
|||
|
|
$installerArgs += "-r"
|
|||
|
|
$installerArgs += "win-x64"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
& dotnet @installerArgs
|
|||
|
|
if ($LASTEXITCODE -ne 0) {
|
|||
|
|
Write-Error "Installer 项目构建失败!"
|
|||
|
|
exit 1
|
|||
|
|
}
|
|||
|
|
Write-Success "Installer 构建完成 -> $OutputInstaller"
|
|||
|
|
|
|||
|
|
# ========== 复制构建脚本到输出目录 ==========
|
|||
|
|
Write-Info "复制构建脚本 ..."
|
|||
|
|
Copy-Item (Join-Path $SolutionDir "build.ps1") $OutputPath
|
|||
|
|
Copy-Item (Join-Path $SolutionDir "build.bat") $OutputPath
|
|||
|
|
Write-Success "构建脚本已复制"
|
|||
|
|
|
|||
|
|
# ========== 生成版本信息 ==========
|
|||
|
|
Write-Info "生成版本信息 ..."
|
|||
|
|
$VersionInfo = @"
|
|||
|
|
Better-Seewo v2.0.1
|
|||
|
|
构建时间: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
|
|||
|
|
构建配置: $Configuration
|
|||
|
|
自包含模式: $SelfContained
|
|||
|
|
.NET SDK: $dotnetVersion
|
|||
|
|
|
|||
|
|
组件列表:
|
|||
|
|
- Better-Seewo.Manager.exe (管理器桌面应用)
|
|||
|
|
- Better-Seewo.Installer.exe (安装向导)
|
|||
|
|
|
|||
|
|
系统要求:
|
|||
|
|
- Windows 10/11
|
|||
|
|
$(if (-not $SelfContained) { " - .NET 6.0 Desktop Runtime`n" })
|
|||
|
|
- 希沃白板 EN5 v5.2.4.9855
|
|||
|
|
|
|||
|
|
作者: 雾启工作室
|
|||
|
|
"@
|
|||
|
|
$VersionInfo | Out-File -Encoding UTF8 (Join-Path $OutputPath "VERSION.txt")
|
|||
|
|
Write-Success "版本信息已生成"
|
|||
|
|
|
|||
|
|
# ========== 统计输出文件 ==========
|
|||
|
|
Write-Info "统计构建产物 ..."
|
|||
|
|
$managerExe = Get-ChildItem $OutputManager -Filter "Better-Seewo.Manager*.exe" -ErrorAction SilentlyContinue
|
|||
|
|
$installerExe = Get-ChildItem $OutputInstaller -Filter "Better-Seewo.Installer*.exe" -ErrorAction SilentlyContinue
|
|||
|
|
|
|||
|
|
if ($managerExe) {
|
|||
|
|
Write-Success "Manager 可执行文件: $($managerExe.Name) ($([math]::Round($managerExe.Length/1MB, 2)) MB)"
|
|||
|
|
} else {
|
|||
|
|
Write-Warning "Manager .exe 未生成(可能为 DLL-only 输出)"
|
|||
|
|
}
|
|||
|
|
if ($installerExe) {
|
|||
|
|
Write-Success "Installer 可执行文件: $($installerExe.Name) ($([math]::Round($installerExe.Length/1MB, 2)) MB)"
|
|||
|
|
} else {
|
|||
|
|
Write-Warning "Installer .exe 未生成(可能为 DLL-only 输出)"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# ========== 完成 ==========
|
|||
|
|
Write-Host ""
|
|||
|
|
Write-Host "========================================" -ForegroundColor Green
|
|||
|
|
Write-Host " 构建成功!" -ForegroundColor Green
|
|||
|
|
Write-Host " 输出目录: $OutputPath" -ForegroundColor Green
|
|||
|
|
Write-Host "========================================" -ForegroundColor Green
|
|||
|
|
Write-Host ""
|
|||
|
|
|
|||
|
|
# 可选:自动打开输出目录
|
|||
|
|
$openDir = Read-Host "是否打开输出目录? (Y/n)"
|
|||
|
|
if ($openDir -eq "" -or $openDir -match "^[Yy]") {
|
|||
|
|
Invoke-Item $OutputPath
|
|||
|
|
}
|