|
1 | | -$ErrorActionPreference = 'Stop' |
2 | | - |
| 1 | +$ErrorActionPreference = "Stop" |
3 | 2 | Set-Location -LiteralPath $PSScriptRoot |
4 | 3 |
|
5 | 4 | $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1' |
6 | 5 | $env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' |
7 | 6 | $env:DOTNET_NOLOGO = '1' |
8 | 7 |
|
9 | | -dotnet tool restore |
10 | | -if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
| 8 | +# ========================================== |
| 9 | +# 1. Restore |
| 10 | +# ========================================== |
| 11 | +Write-Host "Restoring packages..." -ForegroundColor Cyan |
| 12 | +dotnet restore "./AquaMai.slnx" |
| 13 | + |
| 14 | +# ========================================== |
| 15 | +# 2. PreBuild: Generate BuildInfo.g.cs |
| 16 | +# ========================================== |
| 17 | +Write-Host "Generating BuildInfo..." -ForegroundColor Cyan |
| 18 | +try { |
| 19 | + $gitDescribe = git describe --tags --long |
| 20 | + # remove 'v' if exists |
| 21 | + if ($gitDescribe.StartsWith("v")) { |
| 22 | + $gitDescribe = $gitDescribe.Substring(1) |
| 23 | + } |
| 24 | + |
| 25 | + $buildDate = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") |
| 26 | + |
| 27 | + $shortVers = $gitDescribe.Split('-') |
| 28 | + $shortVer = $shortVers[0] |
| 29 | + if ($shortVers.Length -gt 1) { |
| 30 | + $shortVer = "$($shortVers[0]).$($shortVers[1])" |
| 31 | + } |
| 32 | + |
| 33 | + $versionContent = @" |
| 34 | + // Auto-generated file. Do not modify manually. |
| 35 | + namespace AquaMai; |
| 36 | +
|
| 37 | + public static partial class BuildInfo |
| 38 | + { |
| 39 | + public const string Version = "$shortVer"; |
| 40 | + public const string GitVersion = "$gitDescribe"; |
| 41 | + public const string BuildDate = "$buildDate"; |
| 42 | + } |
| 43 | +"@ |
| 44 | + Set-Content "./AquaMai/BuildInfo.g.cs" $versionContent -Encoding UTF8 |
| 45 | +} catch { |
| 46 | + Write-Warning "Failed to generate BuildInfo.g.cs (Git describe failed?): $_" |
| 47 | + # Fallback if needed, or just continue |
| 48 | +} |
11 | 49 |
|
12 | | -taskkill.exe /f /im dotnet.exe |
| 50 | +# ========================================== |
| 51 | +# 3. Build |
| 52 | +# ========================================== |
| 53 | +Write-Host "Building Solution..." -ForegroundColor Cyan |
| 54 | +$Configuration = "Release" |
| 55 | +if ($args.Count -gt 0 -and $args[0] -eq "-Configuration") { |
| 56 | + $Configuration = $args[1] |
| 57 | +} |
13 | 58 |
|
14 | | -dotnet cake @args |
| 59 | +dotnet build "./AquaMai.slnx" -c $Configuration |
15 | 60 | if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
0 commit comments