build.ps1 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # steamAPI Build Script
  2. # Package steamAPI project into a standalone Windows x64 executable
  3. param(
  4. [switch]$Debug,
  5. [switch]$Clean,
  6. [switch]$Help
  7. )
  8. $ErrorActionPreference = "Stop"
  9. $SteamAPIPath = $PSScriptRoot
  10. $OutputDir = Join-Path $SteamAPIPath "publish"
  11. $ProjectFile = Join-Path $SteamAPIPath "steamAPI.csproj"
  12. function Write-ColorOutput {
  13. param(
  14. [string]$Message,
  15. [string]$Color = "White"
  16. )
  17. $colors = @{
  18. "Red" = [ConsoleColor]::Red
  19. "Green" = [ConsoleColor]::Green
  20. "Yellow" = [ConsoleColor]::Yellow
  21. "Cyan" = [ConsoleColor]::Cyan
  22. "White" = [ConsoleColor]::White
  23. }
  24. Write-Host $Message -ForegroundColor $colors[$Color]
  25. }
  26. function Show-Help {
  27. Write-Host ""
  28. Write-Host "steamAPI Build Script"
  29. Write-Host "Usage: .\build.ps1 [options]"
  30. Write-Host ""
  31. Write-Host "Options:"
  32. Write-Host " -Debug Use Debug configuration (default: Release)"
  33. Write-Host " -Clean Clean output directory before building"
  34. Write-Host " -Help Show this help message"
  35. Write-Host ""
  36. Write-Host "Examples:"
  37. Write-Host " .\build.ps1 # Release build"
  38. Write-Host " .\build.ps1 -Debug # Debug build"
  39. Write-Host " .\build.ps1 -Clean # Clean and build"
  40. Write-Host ""
  41. }
  42. if ($Help) {
  43. Show-Help
  44. exit 0
  45. }
  46. Write-ColorOutput "======================================" "Cyan"
  47. Write-ColorOutput " steamAPI Build Script" "Cyan"
  48. Write-ColorOutput "======================================" "Cyan"
  49. Write-Host ""
  50. if (-not (Test-Path $ProjectFile)) {
  51. Write-ColorOutput "Error: Project file not found: $ProjectFile" "Red"
  52. exit 1
  53. }
  54. Write-ColorOutput "[1/4] Restoring NuGet packages..." "Yellow"
  55. Push-Location $SteamAPIPath
  56. try {
  57. dotnet restore $ProjectFile
  58. if ($LASTEXITCODE -ne 0) {
  59. throw "dotnet restore failed"
  60. }
  61. Write-ColorOutput " NuGet packages restored successfully" "Green"
  62. }
  63. finally {
  64. Pop-Location
  65. }
  66. if ($Clean) {
  67. Write-ColorOutput "[2/4] Cleaning output directory..." "Yellow"
  68. if (Test-Path $OutputDir) {
  69. Remove-Item -Path $OutputDir -Recurse -Force
  70. Write-ColorOutput " Clean completed" "Green"
  71. }
  72. else {
  73. Write-ColorOutput " Output directory does not exist, skipping" "Green"
  74. }
  75. }
  76. else {
  77. Write-ColorOutput "[2/4] Skipping clean (use -Clean to clean)" "Yellow"
  78. }
  79. $Configuration = if ($Debug) { "Debug" } else { "Release" }
  80. Write-ColorOutput "[3/4] Building and publishing ($Configuration)..." "Yellow"
  81. Push-Location $SteamAPIPath
  82. try {
  83. $publishArgs = @(
  84. "publish",
  85. $ProjectFile,
  86. "-c", $Configuration,
  87. "-r", "win-x64",
  88. "--self-contained", "true",
  89. "-p:PublishSingleFile=true",
  90. "-p:PublishReadyToRun=true",
  91. "-p:IncludeNativeLibrariesForSelfExtract=true",
  92. "-o", $OutputDir
  93. )
  94. dotnet @publishArgs
  95. if ($LASTEXITCODE -ne 0) {
  96. throw "dotnet publish failed"
  97. }
  98. Write-ColorOutput " Publish completed" "Green"
  99. }
  100. finally {
  101. Pop-Location
  102. }
  103. Write-ColorOutput "[4/4] Build result:" "Yellow"
  104. Write-Host ""
  105. $exePath = Join-Path $OutputDir "steamAPI.exe"
  106. if (Test-Path $exePath) {
  107. $fileInfo = Get-Item $exePath
  108. $sizeMB = [math]::Round($fileInfo.Length / 1MB, 2)
  109. Write-ColorOutput " Executable: $exePath" "Green"
  110. Write-ColorOutput " File size: $sizeMB MB" "Green"
  111. Write-ColorOutput " Output directory: $OutputDir" "Green"
  112. Write-Host ""
  113. Write-ColorOutput " Output files:" "Cyan"
  114. Get-ChildItem $OutputDir | ForEach-Object {
  115. $itemSize = if ($_.PSIsContainer) { "<DIR>" } else { "$([math]::Round($_.Length / 1KB, 1)) KB" }
  116. Write-Host " $($_.Name.PadRight(40)) $itemSize"
  117. }
  118. }
  119. else {
  120. Write-ColorOutput " Error: Build failed, exe file not found" "Red"
  121. exit 1
  122. }
  123. Write-Host ""
  124. Write-ColorOutput "======================================" "Cyan"
  125. Write-ColorOutput " Build successful!" "Green"
  126. Write-ColorOutput "======================================" "Cyan"
  127. Write-Host ""
  128. Write-Host "Run the application:"
  129. Write-Host " .\publish\steamAPI.exe"
  130. Write-Host ""
  131. Write-Host "Or run from project directory:"
  132. Write-Host " cd steam-client\steamAPI"
  133. Write-Host " dotnet run"
  134. Write-Host ""