77 [Parameter (Mandatory = $true , Position = 2 )]
88 [string ]$BuildId ,
99 [Parameter (Mandatory = $true , Position = 3 )]
10- [bool ]$IsPrerelease
10+ [bool ]$IsPrerelease ,
11+ [Parameter (Mandatory = $false , Position = 4 )]
12+ [string ]$TagName = " " ,
13+ [Parameter (Mandatory = $false , Position = 5 )]
14+ [string ]$IsTagBuild = " False"
1115)
1216
17+ $local :IsTagBuildBool = $IsTagBuild -eq " True"
18+
1319Write-Host " SemanticVersion = $SemanticVersion "
1420Write-Host " BuildId = $BuildId "
21+ Write-Host " TagName = $TagName "
22+ Write-Host " IsTagBuild = $IsTagBuild "
1523
1624# Build number must be between 0 - 65534
1725$local :BuildNumber = $BuildId % 65534
@@ -20,41 +28,57 @@ Write-Host "BuildNumber = $($local:BuildNumber)"
2028
2129$local :PackageCodeMarker = " 9999.9999.9999"
2230$local :AssemblyCodeMarker = " 9999.9999.9999.9999"
23- $ local :AssemblyVersion = " ${SemanticVersion} . $ ( $ local :BuildNumber ) "
24- if ($IsPrerelease )
31+
32+ if ($local :IsTagBuildBool )
2533{
26- $local :PackageVersion = " ${SemanticVersion} -dev-$ ( $local :BuildNumber ) "
34+ # Validate tag format
35+ if ($TagName -notmatch ' ^v\d+\.\d+\.\d+$' )
36+ {
37+ Write-Error " ERROR: Tag '$TagName ' does not match expected format 'v<major>.<minor>.<patch>'. Aborting release build."
38+ exit 1
39+ }
40+ $local :TagVersion = $TagName -replace ' ^v' , ' '
41+ $local :PackageVersion = $local :TagVersion
42+ $local :AssemblyVersion = " ${ local:TagVersion } .$ ( $local :BuildNumber ) "
43+ $local :ReleaseTag = $TagName
44+ Write-Host " Tag build detected, using tag name as version"
2745}
2846else
2947{
30- $local :PackageVersion = $SemanticVersion
48+ $local :AssemblyVersion = " ${SemanticVersion} .$ ( $local :BuildNumber ) "
49+ $local :PackageVersion = " ${SemanticVersion} -pre$ ( $local :BuildNumber ) "
50+ $local :ReleaseTag = " dev/v$ ( $local :PackageVersion ) "
51+ Write-Host " Dev build"
3152}
3253Write-Host " PackageCodeMarker = $ ( $local :PackageCodeMarker ) "
3354Write-Host " AssemblyCodeMarker = $ ( $local :AssemblyCodeMarker ) "
3455Write-Host " PackageVersion = $ ( $local :PackageVersion ) "
3556Write-Host " AssemblyVersion = $ ( $local :AssemblyVersion ) "
3657
58+ $local :RepoRoot = $SourceDir
59+
3760Write-Host " Replacing markers in SafeguardDotNet"
38- $local :ProjectFile = (Join-Path $PSScriptRoot " SafeguardDotNet\SafeguardDotNet.csproj" )
61+ $local :ProjectFile = (Join-Path $local :RepoRoot " SafeguardDotNet\SafeguardDotNet.csproj" )
3962(Get-Content $local :ProjectFile - Raw).replace($local :AssemblyCodeMarker , $local :AssemblyVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :ProjectFile
4063(Get-Content $local :ProjectFile - Raw).replace($local :PackageCodeMarker , $local :PackageVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :ProjectFile
4164
4265Write-Host " Replacing markers in SafeguardDotNet.BrowserLogin"
43- $local :ProjectFile = (Join-Path $PSScriptRoot " SafeguardDotNet.BrowserLogin\SafeguardDotNet.BrowserLogin.csproj" )
66+ $local :ProjectFile = (Join-Path $local :RepoRoot " SafeguardDotNet.BrowserLogin\SafeguardDotNet.BrowserLogin.csproj" )
4467(Get-Content $local :ProjectFile - Raw).replace($local :AssemblyCodeMarker , $local :AssemblyVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :ProjectFile
4568(Get-Content $local :ProjectFile - Raw).replace($local :PackageCodeMarker , $local :PackageVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :ProjectFile
4669
4770Write-Host " Replacing markers in SafeguardDotNet.PkceNoninteractiveLogin"
48- $local :ProjectFile = (Join-Path $PSScriptRoot " SafeguardDotNet.PkceNoninteractiveLogin\SafeguardDotNet.PkceNoninteractiveLogin.csproj" )
71+ $local :ProjectFile = (Join-Path $local :RepoRoot " SafeguardDotNet.PkceNoninteractiveLogin\SafeguardDotNet.PkceNoninteractiveLogin.csproj" )
4972(Get-Content $local :ProjectFile - Raw).replace($local :AssemblyCodeMarker , $local :AssemblyVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :ProjectFile
5073(Get-Content $local :ProjectFile - Raw).replace($local :PackageCodeMarker , $local :PackageVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :ProjectFile
5174
5275Write-Host " Replacing markers in SafeguardDotNet.GuiLogin"
53- $local :GuiAssemblyInfoFile = (Join-Path $PSScriptRoot " SafeguardDotNet.GuiLogin\Properties\AssemblyInfo.cs" )
54- $local :GuiNuspec = (Join-Path $PSScriptRoot " SafeguardDotNet.GuiLogin\SafeguardDotNet.GuiLogin.nuspec" )
76+ $local :GuiAssemblyInfoFile = (Join-Path $local :RepoRoot " SafeguardDotNet.GuiLogin\Properties\AssemblyInfo.cs" )
77+ $local :GuiNuspec = (Join-Path $local :RepoRoot " SafeguardDotNet.GuiLogin\SafeguardDotNet.GuiLogin.nuspec" )
5578(Get-Content $local :GuiAssemblyInfoFile - Raw).replace($local :AssemblyCodeMarker , $local :AssemblyVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :GuiAssemblyInfoFile
5679(Get-Content $local :GuiNuspec - Raw).replace($local :PackageCodeMarker , $local :PackageVersion ).TrimEnd() | Set-Content - Encoding UTF8 $local :GuiNuspec
5780
5881
5982Write-Output " ##vso[task.setvariable variable=AssemblyVersion;]$ ( $local :AssemblyVersion ) "
6083Write-Output " ##vso[task.setvariable variable=PackageVersion;]$ ( $local :PackageVersion ) "
84+ Write-Output " ##vso[task.setvariable variable=ReleaseTag;]$ ( $local :ReleaseTag ) "
0 commit comments