# Requires .NET SDK installed. param( [string]$Runtime = "win-x64" ) $OutputDir = Join-Path $PSScriptRoot "bin" $DataDir = Join-Path $OutputDir "data" $TargetExe = Join-Path $OutputDir "NginxMan.exe" $LegacyConfig = Join-Path $OutputDir "nginxman.json" $DataConfig = Join-Path $DataDir "nginxman.json" $NginxAssetExe = Join-Path $PSScriptRoot "nginx\nginx.exe" if (-not (Test-Path $NginxAssetExe)) { Write-Host "Missing embedded Nginx runtime: $NginxAssetExe" -ForegroundColor Red Write-Host "Place the complete Windows Nginx distribution in nginx before building." exit 1 } if (-not (Test-Path $OutputDir)) { New-Item -ItemType Directory -Path $OutputDir | Out-Null } if (-not (Test-Path $DataDir)) { New-Item -ItemType Directory -Path $DataDir | Out-Null } # Preserve the configuration created by older versions before cleaning build artifacts. if ((Test-Path $LegacyConfig) -and -not (Test-Path $DataConfig)) { Move-Item -LiteralPath $LegacyConfig -Destination $DataConfig } # The release folder deliberately contains only the executable and its data folder. Get-ChildItem -Force -Path $OutputDir | Where-Object { $_.Name -ne "data" } | Remove-Item -Recurse -Force New-Item -ItemType Directory -Path $DataDir -Force | Out-Null dotnet publish .\NginxMan.csproj ` -c Release ` -r $Runtime ` -p:SelfContained=true ` -p:PublishSingleFile=true ` -p:IncludeNativeLibrariesForSelfExtract=true ` -p:DebugType=None ` -p:DebugSymbols=false ` -o $OutputDir if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # Remove any unexpected publish byproducts while keeping the executable and persistent data. Get-ChildItem -Force -Path $OutputDir | Where-Object { $_.Name -ne "data" -and $_.Name -ne "NginxMan.exe" } | Remove-Item -Recurse -Force Write-Host "OutputDir: $OutputDir" Write-Host "MainExe: $TargetExe"