Parcourir la source

chore(build): 优化Windows发布流程为单文件自包含

将构建改为Release模式发布,生成自包含单文件并更新忽略规则
yangkaixiang il y a 1 mois
Parent
commit
4c2b1d7ad7
2 fichiers modifiés avec 15 ajouts et 6 suppressions
  1. 1 0
      .gitignore
  2. 14 6
      build.ps1

+ 1 - 0
.gitignore

@@ -26,6 +26,7 @@ server/coverage.out
 windows/**/bin/
 windows/**/obj/
 windows/.vs/
+publish/
 
 # Temp
 tmp/

+ 14 - 6
build.ps1

@@ -4,19 +4,27 @@ $ErrorActionPreference = "Stop"
 $repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
 $windowsDir = Join-Path $repoRoot "windows"
 $serverDir = Join-Path $repoRoot "server"
-$windowsSolution = Join-Path $windowsDir "NetworkTool.Client.sln"
+$windowsProject = Join-Path $windowsDir "NetworkTool.Client\NetworkTool.Client.csproj"
+$windowsPublishOutput = Join-Path $repoRoot "publish\win-x64"
 $serverLinuxOutput = Join-Path $serverDir "networktool-server-linux-amd64"
 
-if (-not (Test-Path -LiteralPath $windowsSolution)) {
-    throw "Windows solution not found: $windowsSolution"
+if (-not (Test-Path -LiteralPath $windowsProject)) {
+    throw "Windows project not found: $windowsProject"
 }
 
 if (-not (Test-Path -LiteralPath $serverDir)) {
     throw "Server directory not found: $serverDir"
 }
 
-Write-Host "[1/2] Building Windows client (Debug)..."
-dotnet build $windowsSolution -c Debug
+Write-Host "[1/2] Publishing Windows client (Release, self-contained win-x64)..."
+dotnet publish $windowsProject `
+    -c Release `
+    -r win-x64 `
+    --self-contained true `
+    -p:PublishSingleFile=true `
+    -p:IncludeNativeLibrariesForSelfExtract=true `
+    -p:EnableCompressionInSingleFile=true `
+    -o $windowsPublishOutput
 
 $previousGoos = $env:GOOS
 $previousGoarch = $env:GOARCH
@@ -38,5 +46,5 @@ finally {
 }
 
 Write-Host "Build completed."
-Write-Host "Windows client output: windows/NetworkTool.Client/bin/Debug/net9.0-windows/"
+Write-Host "Windows client output: publish/win-x64/"
 Write-Host "Server Linux output: server/networktool-server-linux-amd64"