build.ps1 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. $windowsSolution = Join-Path $windowsDir "NetworkTool.Client.sln"
  7. $serverLinuxOutput = Join-Path $serverDir "networktool-server-linux-amd64"
  8. if (-not (Test-Path -LiteralPath $windowsSolution)) {
  9. throw "Windows solution not found: $windowsSolution"
  10. }
  11. if (-not (Test-Path -LiteralPath $serverDir)) {
  12. throw "Server directory not found: $serverDir"
  13. }
  14. Write-Host "[1/2] Building Windows client (Debug)..."
  15. dotnet build $windowsSolution -c Debug
  16. $previousGoos = $env:GOOS
  17. $previousGoarch = $env:GOARCH
  18. $previousCgoEnabled = $env:CGO_ENABLED
  19. try {
  20. Write-Host "[2/2] Building server for Linux amd64..."
  21. Set-Location -LiteralPath $serverDir
  22. $env:GOOS = "linux"
  23. $env:GOARCH = "amd64"
  24. $env:CGO_ENABLED = "0"
  25. go build -o $serverLinuxOutput ./cmd/networktool-server
  26. }
  27. finally {
  28. $env:GOOS = $previousGoos
  29. $env:GOARCH = $previousGoarch
  30. $env:CGO_ENABLED = $previousCgoEnabled
  31. Set-Location -LiteralPath $repoRoot
  32. }
  33. Write-Host "Build completed."
  34. Write-Host "Windows client output: windows/NetworkTool.Client/bin/Debug/net9.0-windows/"
  35. Write-Host "Server Linux output: server/networktool-server-linux-amd64"