# Publish UtopiaCanteen.BackendService to a folder (default C:\UtopiaCanteenBackend). # Default: self-contained win-x64 (no .NET runtime required on target PC). param( [string]$OutputPath = "C:\UtopiaCanteenBackend", [ValidateSet("Debug", "Release")] [string]$Configuration = "Release", [string]$Runtime = "win-x64", [switch]$FrameworkDependent, [switch]$SelfContained ) $ErrorActionPreference = "Stop" $Root = Split-Path -Parent $PSScriptRoot $Project = Join-Path $Root "UtopiaCanteen.BackendService\UtopiaCanteen.BackendService.csproj" if (-not (Test-Path $Project)) { throw "Project not found: $Project" } # Self-contained unless -FrameworkDependent is passed. $isSelfContained = -not $FrameworkDependent if ($SelfContained) { $isSelfContained = $true } $publishArgs = @( "publish", $Project, "-c", $Configuration, "-o", $OutputPath ) if ($isSelfContained) { $publishArgs += @("-r", $Runtime, "--self-contained", "true") Write-Host "Publishing backend ($Configuration, self-contained $Runtime) -> $OutputPath" } else { $publishArgs += @("--self-contained", "false") Write-Host "Publishing backend ($Configuration, framework-dependent) -> $OutputPath" Write-Host "Target PC must have .NET 8 Desktop Runtime installed." } dotnet @publishArgs if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed with exit code $LASTEXITCODE" } $appsettings = Join-Path $OutputPath "appsettings.json" if (Test-Path $appsettings) { Write-Host "Edit connection strings in: $appsettings" } Write-Host @" Done. Executable: $(Join-Path $OutputPath 'UtopiaCanteen.BackendService.exe') Deploy: copy the entire folder '$OutputPath' to the server PC. $(if ($isSelfContained) { "Self-contained: .NET runtime is included; no separate install needed." } else { "Framework-dependent: install .NET 8 Runtime on the server." }) "@