openthebox/publish.ps1

54 lines
1.6 KiB
PowerShell
Raw Normal View History

<#
.SYNOPSIS
Builds a self-contained single-file executable for distribution.
.DESCRIPTION
Publishes Open The Box as a standalone .exe that includes the .NET runtime.
No .NET SDK or runtime installation needed on target machines.
.PARAMETER Runtime
Target runtime identifier. Default: win-x64
Examples: win-x64, win-arm64, linux-x64, osx-x64
#>
param(
[string]$Runtime = "win-x64"
)
$ErrorActionPreference = "Stop"
Write-Host "=== Open The Box - Publish ===" -ForegroundColor Cyan
Write-Host "Runtime: $Runtime"
Write-Host ""
$OutputDir = Join-Path $PSScriptRoot "publish" $Runtime
# Clean previous publish
if (Test-Path $OutputDir) {
Remove-Item $OutputDir -Recurse -Force
}
Write-Host "Publishing self-contained single-file executable..." -ForegroundColor Yellow
dotnet publish src/OpenTheBox/OpenTheBox.csproj `
-c Release `
-r $Runtime `
--self-contained true `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-o $OutputDir
if ($LASTEXITCODE -ne 0) {
Write-Host "Publish failed!" -ForegroundColor Red
exit 1
}
# Show output
Write-Host ""
Write-Host "Published to: $OutputDir" -ForegroundColor Green
$exe = Get-ChildItem $OutputDir -Filter "OpenTheBox*" | Where-Object { $_.Extension -in ".exe", "" } | Select-Object -First 1
if ($exe) {
$sizeMB = [math]::Round($exe.Length / 1MB, 1)
Write-Host "Executable: $($exe.Name) ($sizeMB MB)" -ForegroundColor Green
}
Write-Host ""
Write-Host "To distribute, copy the entire '$OutputDir' folder." -ForegroundColor Cyan
Write-Host "The content/ folder must remain alongside the executable." -ForegroundColor Cyan