param( [string]$Rid = "win-x64", [bool]$SelfContained = $false, [bool]$SingleFile = $true, [bool]$EnableCompressionInSingleFile = $true, [bool]$ReadyToRun = $false, [bool]$Trim = $false, [bool]$InvariantGlobalization = $false ) $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest $repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..") $project = Join-Path $repoRoot "TimerApp.csproj" $artifactsDir = Join-Path $repoRoot "artifacts" $distDir = Join-Path $repoRoot "dist" New-Item -ItemType Directory -Force -Path $distDir | Out-Null $EnableCompressionInSingleFile = $EnableCompressionInSingleFile -and $SelfContained $variantParts = @() $variantParts += $(if ($SelfContained) { "sc" } else { "fd" }) $variantParts += $(if ($SingleFile) { "single" } else { "multi" }) if ($SingleFile -and $EnableCompressionInSingleFile) { $variantParts += "comp" } if ($ReadyToRun) { $variantParts += "r2r" } if ($Trim) { $variantParts += "trim" } if ($InvariantGlobalization) { $variantParts += "invglob" } $variant = ($variantParts -join "-") $defaultVariant = "fd-single" $publishBaseDir = Join-Path $artifactsDir "publish" $publishDir = Join-Path (Join-Path $publishBaseDir $Rid) $variant New-Item -ItemType Directory -Force -Path $publishDir | Out-Null $props = @( "-p:SelfContained=$SelfContained", "-p:PublishSingleFile=$SingleFile", "-p:PublishReadyToRun=$ReadyToRun", "-p:DebugType=None", "-p:DebugSymbols=false" ) if ($SingleFile) { $props += "-p:IncludeNativeLibrariesForSelfExtract=true" if ($SelfContained) { $props += "-p:EnableCompressionInSingleFile=$EnableCompressionInSingleFile" } } if ($Trim) { $props += "-p:PublishTrimmed=true" $props += "-p:TrimMode=partial" } if ($InvariantGlobalization) { $props += "-p:InvariantGlobalization=true" } dotnet publish $project ` -c Release ` -r $Rid ` @props ` -o $publishDir if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed with exit code $LASTEXITCODE" } $zipName = if ($variant -eq $defaultVariant) { "TimerApp-Portable-$Rid.zip" } else { "TimerApp-Portable-$Rid-$variant.zip" } $zipPath = Join-Path $distDir $zipName if (Test-Path $zipPath) { try { [System.IO.File]::Delete($zipPath) } catch { } } Compress-Archive -Path (Join-Path $publishDir "*") -DestinationPath $zipPath -Force $mainExe = Join-Path $publishDir "TimerApp.exe" if (Test-Path $mainExe) { $exeMiB = [Math]::Round(((Get-Item $mainExe).Length / 1MB), 1) Write-Host "EXE size: $exeMiB MiB" } $zipMiB = [Math]::Round(((Get-Item $zipPath).Length / 1MB), 1) Write-Host "ZIP size: $zipMiB MiB" Write-Host "Portable zip created:" Write-Host " $zipPath"