diff --git a/src/build.ps1 b/src/build.ps1 index aa7ebd0..bc3dd5b 100644 --- a/src/build.ps1 +++ b/src/build.ps1 @@ -5,7 +5,7 @@ pwsh ./build.ps1 # build all pwsh ./build.ps1 -Targets win # just Windows 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( @@ -60,17 +60,40 @@ function Invoke-InProjectDir { } } -# --- Version (git tag 'vX.Y.Z' > explicit > empty) --- -if (-not $Version) { +# --- Version (default from Directory.Build.props unless overridden) --- +function Get-VersionFromProps { + param([Parameter(Mandatory=$true)][string]$PropsPath) + if (-not (Test-Path $PropsPath)) { return $null } try { - $tag = (git describe --tags --abbrev=0) 2>$null - if ($LASTEXITCODE -eq 0 -and $tag) { $Version = $tag.TrimStart('v') } + $xml = [xml](Get-Content -Raw -Path $PropsPath) + $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 { } + 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) 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 --- @@ -90,7 +113,7 @@ if ($Targets -contains 'win') { '-p:IncludeNativeLibrariesForSelfExtract=true', '-o', $OutWin ) - if ($Version) { $args += "-p:Version=$Version" } + if ($ExplicitVersion) { $args += "-p:Version=$Version" } # Prevent '+' being appended to informational version in artifacts $args += '-p:IncludeSourceRevisionInInformationalVersion=false' Invoke-InProjectDir -ProjectPath $ProjDesktop @args @@ -105,7 +128,7 @@ if ($Targets -contains 'web') { '--self-contained', 'true', '-o', $OutWeb ) - if ($Version) { $args += "-p:Version=$Version" } + if ($ExplicitVersion) { $args += "-p:Version=$Version" } $args += '-p:IncludeSourceRevisionInInformationalVersion=false' Invoke-InProjectDir -ProjectPath $ProjWeb @args @@ -125,7 +148,7 @@ if ($Targets -contains 'android') { '-p:AndroidPackageFormat=apk', '-o', $OutDroid ) - if ($Version) { $baseArgs += "-p:Version=$Version" } + if ($ExplicitVersion) { $baseArgs += "-p:Version=$Version" } $baseArgs += '-p:IncludeSourceRevisionInInformationalVersion=false' # Unsigned build