38 lines
1.7 KiB
PowerShell
38 lines
1.7 KiB
PowerShell
param(
|
|
[ValidateSet('win-x64', 'win-x86', 'win-arm64')]
|
|
[string[]] $Architecture = @('win-x64', 'win-x86', 'win-arm64')
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$project = Join-Path $PSScriptRoot 'DailyFileSync.csproj'
|
|
$dist = Join-Path $PSScriptRoot 'dist'
|
|
$staging = Join-Path $PSScriptRoot 'obj\standalone'
|
|
New-Item -ItemType Directory -Path $dist, $staging -Force | Out-Null
|
|
$staging = (Resolve-Path -LiteralPath $staging).ProviderPath
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
foreach ($runtime in $Architecture) {
|
|
$package = "DailyFileSync-standalone-$runtime"
|
|
$workingDirectory = Join-Path $staging ([guid]::NewGuid().ToString('N'))
|
|
$publishDirectory = Join-Path $workingDirectory $package
|
|
$stagedArchive = Join-Path $workingDirectory "$package.zip"
|
|
$archive = Join-Path $dist "$package.zip"
|
|
New-Item -ItemType Directory -Path $workingDirectory | Out-Null
|
|
|
|
try {
|
|
& dotnet publish $project --configuration Release --runtime $runtime --self-contained true --output $publishDirectory -p:DebugType=none
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Publishing failed for $runtime. See the dotnet output above."
|
|
}
|
|
|
|
[System.IO.Compression.ZipFile]::CreateFromDirectory($publishDirectory, $stagedArchive, [System.IO.Compression.CompressionLevel]::Optimal, $true)
|
|
Move-Item -LiteralPath $stagedArchive -Destination $archive -Force
|
|
Write-Output $archive
|
|
} finally {
|
|
$resolvedDirectory = (Resolve-Path -LiteralPath $workingDirectory).ProviderPath
|
|
if ((Split-Path -Parent $resolvedDirectory) -eq $staging) {
|
|
Remove-Item -LiteralPath $resolvedDirectory -Recurse -Force
|
|
}
|
|
}
|
|
}
|