-
Notifications
You must be signed in to change notification settings - Fork 5
/
azure-pipelines-version.ps1
36 lines (29 loc) · 1.7 KB
/
azure-pipelines-version.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
dotnet-gitversion /output file /outputfile .git/GitVersion.json
$gitversion = Get-Content -Path .git/GitVersion.json -Encoding UTF8 | ConvertFrom-Json
foreach ($Property in $gitversion.PSObject.Properties) {
Write-Output "$($Property.Name) = $($Property.Value)"
Set-Variable -Name $Property.Name -Value $Property.Value -Scope Global -Visibility Public
}
# If it's tagged so that's the version
if ($BranchName.StartsWith("tags/")) {
$InformationalVersion = $BranchName.Split("/")[1]
} else {
$AssemblySemVer = $AssemblySemFileVer = "$($MajorMinorPatch).$($CommitsSinceVersionSourcePadded)"
$InformationalVersion = "$($MajorMinorPatch)-$($EscapedBranchName).build-$($CommitsSinceVersionSource).Sha.$($ShortSha)"
}
Write-Output "AssemblySemVer: $($AssemblySemVer)"
Write-Output "AssemblySemFileVer: $($AssemblySemFileVer)"
Write-Output "InformationalVersion: $($InformationalVersion)"
$csprojs = Get-ChildItem -Path .\*.csproj -Recurse -Force
foreach ($csproj in $csprojs) {
$csprojText = Get-Content -Path $csproj.fullName -Encoding UTF8
$csprojText = $csprojText -creplace '(?s)<AssemblyVersion>.*?</AssemblyVersion>', "<AssemblyVersion>$($AssemblySemVer)</AssemblyVersion>"
$csprojText = $csprojText -creplace '(?s)<FileVersion>.*?</FileVersion>', "<FileVersion>$($AssemblySemFileVer)</FileVersion>"
$csprojText = $csprojText -creplace '(?s)<Version>.*?</Version>', "<Version>$($InformationalVersion)</Version>"
Set-Content -Path $csproj.fullName -Value $csprojText -Encoding UTF8
Write-Output "Patching project versions '$($csproj.fullName)'"
}
# On Azure Pipelines update build number
if ($Env:AGENT_NAME -ne "") {
Write-Host "##vso[build.updatebuildnumber]$($InformationalVersion)"
}