build: default version from Directory.Build.props; allow -Version override
Remove git tag fallback and read AppVersion/PrereleaseLabel from props. Only pass -p:Version when override is provided; otherwise defer to MSBuild evaluation.
This commit is contained in:
parent
e911615845
commit
8c165c90a3
1 changed files with 33 additions and 10 deletions
|
@ -5,7 +5,7 @@
|
||||||
pwsh ./build.ps1 # build all
|
pwsh ./build.ps1 # build all
|
||||||
pwsh ./build.ps1 -Targets win # just Windows
|
pwsh ./build.ps1 -Targets win # just Windows
|
||||||
pwsh ./build.ps1 -Targets web,android # pick targets
|
pwsh ./build.ps1 -Targets web,android # pick targets
|
||||||
pwsh ./build.ps1 -Version 1.2.3 # override version (else tries git tag)
|
pwsh ./build.ps1 -Version 1.2.3 # override version (default comes from Directory.Build.props)
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
param(
|
||||||
|
@ -60,17 +60,40 @@ function Invoke-InProjectDir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Version (git tag 'vX.Y.Z' > explicit > empty) ---
|
# --- Version (default from Directory.Build.props unless overridden) ---
|
||||||
if (-not $Version) {
|
function Get-VersionFromProps {
|
||||||
|
param([Parameter(Mandatory=$true)][string]$PropsPath)
|
||||||
|
if (-not (Test-Path $PropsPath)) { return $null }
|
||||||
try {
|
try {
|
||||||
$tag = (git describe --tags --abbrev=0) 2>$null
|
$xml = [xml](Get-Content -Raw -Path $PropsPath)
|
||||||
if ($LASTEXITCODE -eq 0 -and $tag) { $Version = $tag.TrimStart('v') }
|
$groups = @($xml.Project.PropertyGroup)
|
||||||
|
$app = ($groups | ForEach-Object { $_.AppVersion } | Where-Object { $_ -and $_.Trim() -ne '' } | Select-Object -First 1)
|
||||||
|
$pre = ($groups | ForEach-Object { $_.PrereleaseLabel } | Where-Object { $_ -and $_.Trim() -ne '' } | Select-Object -First 1)
|
||||||
|
if ($app) {
|
||||||
|
if ($pre) { return "$app-$pre" }
|
||||||
|
return $app
|
||||||
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
|
return $null
|
||||||
}
|
}
|
||||||
if ($Version) {
|
|
||||||
|
$ExplicitVersion = $false
|
||||||
|
if ($PSBoundParameters.ContainsKey('Version') -and $Version) { $ExplicitVersion = $true }
|
||||||
|
|
||||||
|
$DerivedVersion = $null
|
||||||
|
if (-not $ExplicitVersion) {
|
||||||
|
$DerivedVersion = Get-VersionFromProps (Join-Path $Root 'Directory.Build.props')
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ExplicitVersion) {
|
||||||
# Normalize to SemVer with 3 numeric segments (X.Y.Z)
|
# Normalize to SemVer with 3 numeric segments (X.Y.Z)
|
||||||
if ($Version -match '^(\d+)\.(\d+)$') { $Version = "$Version.0" }
|
if ($Version -match '^(\d+)\.(\d+)$') { $Version = "$Version.0" }
|
||||||
Write-Host "Using Version: $Version" -ForegroundColor Yellow
|
Write-Host "Using Version (override): $Version" -ForegroundColor Yellow
|
||||||
|
} elseif ($DerivedVersion) {
|
||||||
|
if ($DerivedVersion -match '^(\d+)\.(\d+)$') { $DerivedVersion = "$DerivedVersion.0" }
|
||||||
|
Write-Host "Using Version (from Directory.Build.props): $DerivedVersion" -ForegroundColor Yellow
|
||||||
|
} else {
|
||||||
|
Write-Host "No explicit version provided; MSBuild will compute Version from Directory.Build.props." -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Ensure SDK/workloads present ---
|
# --- Ensure SDK/workloads present ---
|
||||||
|
@ -90,7 +113,7 @@ if ($Targets -contains 'win') {
|
||||||
'-p:IncludeNativeLibrariesForSelfExtract=true',
|
'-p:IncludeNativeLibrariesForSelfExtract=true',
|
||||||
'-o', $OutWin
|
'-o', $OutWin
|
||||||
)
|
)
|
||||||
if ($Version) { $args += "-p:Version=$Version" }
|
if ($ExplicitVersion) { $args += "-p:Version=$Version" }
|
||||||
# Prevent '+<sha>' being appended to informational version in artifacts
|
# Prevent '+<sha>' being appended to informational version in artifacts
|
||||||
$args += '-p:IncludeSourceRevisionInInformationalVersion=false'
|
$args += '-p:IncludeSourceRevisionInInformationalVersion=false'
|
||||||
Invoke-InProjectDir -ProjectPath $ProjDesktop @args
|
Invoke-InProjectDir -ProjectPath $ProjDesktop @args
|
||||||
|
@ -105,7 +128,7 @@ if ($Targets -contains 'web') {
|
||||||
'--self-contained', 'true',
|
'--self-contained', 'true',
|
||||||
'-o', $OutWeb
|
'-o', $OutWeb
|
||||||
)
|
)
|
||||||
if ($Version) { $args += "-p:Version=$Version" }
|
if ($ExplicitVersion) { $args += "-p:Version=$Version" }
|
||||||
$args += '-p:IncludeSourceRevisionInInformationalVersion=false'
|
$args += '-p:IncludeSourceRevisionInInformationalVersion=false'
|
||||||
Invoke-InProjectDir -ProjectPath $ProjWeb @args
|
Invoke-InProjectDir -ProjectPath $ProjWeb @args
|
||||||
|
|
||||||
|
@ -125,7 +148,7 @@ if ($Targets -contains 'android') {
|
||||||
'-p:AndroidPackageFormat=apk',
|
'-p:AndroidPackageFormat=apk',
|
||||||
'-o', $OutDroid
|
'-o', $OutDroid
|
||||||
)
|
)
|
||||||
if ($Version) { $baseArgs += "-p:Version=$Version" }
|
if ($ExplicitVersion) { $baseArgs += "-p:Version=$Version" }
|
||||||
$baseArgs += '-p:IncludeSourceRevisionInInformationalVersion=false'
|
$baseArgs += '-p:IncludeSourceRevisionInInformationalVersion=false'
|
||||||
|
|
||||||
# Unsigned build
|
# Unsigned build
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue