build.ps1 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Set-StrictMode -Version Latest
  2. $ErrorActionPreference = "Stop"
  3. $repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
  4. $windowsDir = Join-Path $repoRoot "windows"
  5. $serverDir = Join-Path $repoRoot "server"
  6. $windowsProject = Join-Path $windowsDir "NetworkTool.Client\NetworkTool.Client.csproj"
  7. $windowsPublishOutput = Join-Path $repoRoot "publish\win-x64"
  8. $serverLinuxOutput = Join-Path $serverDir "networktool-server-linux-amd64"
  9. if (-not (Test-Path -LiteralPath $windowsProject)) {
  10. throw "Windows project not found: $windowsProject"
  11. }
  12. if (-not (Test-Path -LiteralPath $serverDir)) {
  13. throw "Server directory not found: $serverDir"
  14. }
  15. Write-Host "[1/2] Publishing Windows client (Release, self-contained win-x64)..."
  16. dotnet publish $windowsProject `
  17. -c Release `
  18. -r win-x64 `
  19. --self-contained true `
  20. -p:PublishSingleFile=true `
  21. -p:IncludeNativeLibrariesForSelfExtract=true `
  22. -p:EnableCompressionInSingleFile=true `
  23. -o $windowsPublishOutput
  24. $previousGoos = $env:GOOS
  25. $previousGoarch = $env:GOARCH
  26. $previousCgoEnabled = $env:CGO_ENABLED
  27. try {
  28. Write-Host "[2/2] Building server for Linux amd64..."
  29. Set-Location -LiteralPath $serverDir
  30. $env:GOOS = "linux"
  31. $env:GOARCH = "amd64"
  32. $env:CGO_ENABLED = "0"
  33. go build -o $serverLinuxOutput ./cmd/networktool-server
  34. }
  35. finally {
  36. $env:GOOS = $previousGoos
  37. $env:GOARCH = $previousGoarch
  38. $env:CGO_ENABLED = $previousCgoEnabled
  39. Set-Location -LiteralPath $repoRoot
  40. }
  41. Write-Host "Build completed."
  42. Write-Host "Windows client output: publish/win-x64/"
  43. Write-Host "Server Linux output: server/networktool-server-linux-amd64"