| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- # steamAPI Build Script
- # Package steamAPI project into a standalone Windows x64 executable
- param(
- [switch]$Debug,
- [switch]$Clean,
- [switch]$Help
- )
- $ErrorActionPreference = "Stop"
- $SteamAPIPath = $PSScriptRoot
- $OutputDir = Join-Path $SteamAPIPath "publish"
- $ProjectFile = Join-Path $SteamAPIPath "steamAPI.csproj"
- function Write-ColorOutput {
- param(
- [string]$Message,
- [string]$Color = "White"
- )
- $colors = @{
- "Red" = [ConsoleColor]::Red
- "Green" = [ConsoleColor]::Green
- "Yellow" = [ConsoleColor]::Yellow
- "Cyan" = [ConsoleColor]::Cyan
- "White" = [ConsoleColor]::White
- }
- Write-Host $Message -ForegroundColor $colors[$Color]
- }
- function Show-Help {
- Write-Host ""
- Write-Host "steamAPI Build Script"
- Write-Host "Usage: .\build.ps1 [options]"
- Write-Host ""
- Write-Host "Options:"
- Write-Host " -Debug Use Debug configuration (default: Release)"
- Write-Host " -Clean Clean output directory before building"
- Write-Host " -Help Show this help message"
- Write-Host ""
- Write-Host "Examples:"
- Write-Host " .\build.ps1 # Release build"
- Write-Host " .\build.ps1 -Debug # Debug build"
- Write-Host " .\build.ps1 -Clean # Clean and build"
- Write-Host ""
- }
- if ($Help) {
- Show-Help
- exit 0
- }
- Write-ColorOutput "======================================" "Cyan"
- Write-ColorOutput " steamAPI Build Script" "Cyan"
- Write-ColorOutput "======================================" "Cyan"
- Write-Host ""
- if (-not (Test-Path $ProjectFile)) {
- Write-ColorOutput "Error: Project file not found: $ProjectFile" "Red"
- exit 1
- }
- Write-ColorOutput "[1/4] Restoring NuGet packages..." "Yellow"
- Push-Location $SteamAPIPath
- try {
- dotnet restore $ProjectFile
- if ($LASTEXITCODE -ne 0) {
- throw "dotnet restore failed"
- }
- Write-ColorOutput " NuGet packages restored successfully" "Green"
- }
- finally {
- Pop-Location
- }
- if ($Clean) {
- Write-ColorOutput "[2/4] Cleaning output directory..." "Yellow"
- if (Test-Path $OutputDir) {
- Remove-Item -Path $OutputDir -Recurse -Force
- Write-ColorOutput " Clean completed" "Green"
- }
- else {
- Write-ColorOutput " Output directory does not exist, skipping" "Green"
- }
- }
- else {
- Write-ColorOutput "[2/4] Skipping clean (use -Clean to clean)" "Yellow"
- }
- $Configuration = if ($Debug) { "Debug" } else { "Release" }
- Write-ColorOutput "[3/4] Building and publishing ($Configuration)..." "Yellow"
- Push-Location $SteamAPIPath
- try {
- $publishArgs = @(
- "publish",
- $ProjectFile,
- "-c", $Configuration,
- "-r", "win-x64",
- "--self-contained", "true",
- "-p:PublishSingleFile=true",
- "-p:PublishReadyToRun=true",
- "-p:IncludeNativeLibrariesForSelfExtract=true",
- "-o", $OutputDir
- )
- dotnet @publishArgs
- if ($LASTEXITCODE -ne 0) {
- throw "dotnet publish failed"
- }
- Write-ColorOutput " Publish completed" "Green"
- }
- finally {
- Pop-Location
- }
- Write-ColorOutput "[4/4] Build result:" "Yellow"
- Write-Host ""
- $exePath = Join-Path $OutputDir "steamAPI.exe"
- if (Test-Path $exePath) {
- $fileInfo = Get-Item $exePath
- $sizeMB = [math]::Round($fileInfo.Length / 1MB, 2)
- Write-ColorOutput " Executable: $exePath" "Green"
- Write-ColorOutput " File size: $sizeMB MB" "Green"
- Write-ColorOutput " Output directory: $OutputDir" "Green"
- Write-Host ""
- Write-ColorOutput " Output files:" "Cyan"
- Get-ChildItem $OutputDir | ForEach-Object {
- $itemSize = if ($_.PSIsContainer) { "<DIR>" } else { "$([math]::Round($_.Length / 1KB, 1)) KB" }
- Write-Host " $($_.Name.PadRight(40)) $itemSize"
- }
- }
- else {
- Write-ColorOutput " Error: Build failed, exe file not found" "Red"
- exit 1
- }
- Write-Host ""
- Write-ColorOutput "======================================" "Cyan"
- Write-ColorOutput " Build successful!" "Green"
- Write-ColorOutput "======================================" "Cyan"
- Write-Host ""
- Write-Host "Run the application:"
- Write-Host " .\publish\steamAPI.exe"
- Write-Host ""
- Write-Host "Or run from project directory:"
- Write-Host " cd steam-client\steamAPI"
- Write-Host " dotnet run"
- Write-Host ""
|