|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [ValidatePattern('^\d+\.\d+\.\d+([-.][0-9A-Za-z.-]+)?$')] |
| 4 | + [string]$Version = '1.0.0', |
| 5 | + |
| 6 | + [ValidateSet('win-x64', 'win-x86')] |
| 7 | + [string]$Runtime = 'win-x64' |
| 8 | +) |
| 9 | + |
| 10 | +$ErrorActionPreference = 'Stop' |
| 11 | + |
| 12 | +$projectRoot = Split-Path -Parent $PSScriptRoot |
| 13 | +$projectFile = Join-Path $projectRoot 'SQLBakVersion.csproj' |
| 14 | +$artifactsDirectory = Join-Path $projectRoot 'artifacts' |
| 15 | +$releaseName = "SQLBakVersion" |
| 16 | +$publishDirectory = Join-Path $artifactsDirectory $releaseName |
| 17 | +$zipPath = Join-Path $artifactsDirectory "$releaseName.zip" |
| 18 | + |
| 19 | +if (-not (Test-Path -LiteralPath $projectFile)) { |
| 20 | + throw "Project file was not found: $projectFile" |
| 21 | +} |
| 22 | + |
| 23 | +New-Item -ItemType Directory -Path $artifactsDirectory -Force | Out-Null |
| 24 | + |
| 25 | +if (Test-Path -LiteralPath $publishDirectory) { |
| 26 | + Remove-Item -LiteralPath $publishDirectory -Recurse -Force |
| 27 | +} |
| 28 | +if (Test-Path -LiteralPath $zipPath) { |
| 29 | + Remove-Item -LiteralPath $zipPath -Force |
| 30 | +} |
| 31 | + |
| 32 | +Write-Host "Restoring packages for $Runtime..." |
| 33 | +dotnet restore $projectFile --runtime $Runtime |
| 34 | + |
| 35 | +if ($LASTEXITCODE -ne 0) { |
| 36 | + throw "dotnet restore failed with exit code $LASTEXITCODE." |
| 37 | +} |
| 38 | + |
| 39 | +Write-Host "Publishing $releaseName..." |
| 40 | +dotnet publish $projectFile ` |
| 41 | + --configuration Release ` |
| 42 | + --runtime $Runtime ` |
| 43 | + --self-contained true ` |
| 44 | + --no-restore ` |
| 45 | + -p:PublishSingleFile=true ` |
| 46 | + -p:IncludeNativeLibrariesForSelfExtract=true ` |
| 47 | + -p:Version=$Version ` |
| 48 | + --output $publishDirectory |
| 49 | + |
| 50 | +if ($LASTEXITCODE -ne 0) { |
| 51 | + throw "dotnet publish failed with exit code $LASTEXITCODE." |
| 52 | +} |
| 53 | + |
| 54 | +Copy-Item -LiteralPath (Join-Path $projectRoot 'README.md') -Destination $publishDirectory |
| 55 | +Compress-Archive -Path (Join-Path $publishDirectory '*') -DestinationPath $zipPath -CompressionLevel Optimal |
| 56 | + |
| 57 | +Write-Host "Release ZIP created: $zipPath" -ForegroundColor Green |
0 commit comments