Skip to content

Commit ce51866

Browse files
author
Yaroslav Zhmayev
committed
add gittool
1 parent f718b16 commit ce51866

File tree

3 files changed

+48
-58
lines changed

3 files changed

+48
-58
lines changed

CodeCave.Threejs.Revit.Exporter.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
99
ProjectSection(SolutionItems) = preProject
1010
.editorconfig = .editorconfig
1111
.gitignore = .gitignore
12+
azure-pipelines-version.ps1 = azure-pipelines-version.ps1
1213
azure-pipelines.yml = azure-pipelines.yml
1314
CodeAnalysis.ruleset = CodeAnalysis.ruleset
1415
Directory.Build.props = Directory.Build.props

azure-pipelines-version.ps1

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

azure-pipelines.yml

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,20 @@ steps:
2020
inputs:
2121
packageType: sdk
2222
version: '6.0.x'
23-
# version: '3.1.201'
2423

24+
- task: DotNetCoreCLI@2
25+
displayName: 'Install GitVersion'
26+
inputs:
27+
command: 'custom'
28+
custom: 'tool'
29+
arguments: 'update -g gitversion.tool --version 5.5.*'
2530

26-
#- task: BuildVersioning@0
27-
# displayName: 'Patching assembly versions (unstable build)'
28-
# condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
29-
# inputs:
30-
# sourcePath: 'src'
31-
# versionSource: 'gitversion'
32-
# doInstallGitVersion: true
33-
# GitVersionInstallerSource: 'custom'
34-
# GitVersionInstallerUrl: 'https://packages.chocolatey.org/GitVersion.Portable.5.0.1.nupkg'
35-
# paramAssemblyVersion: '3'
36-
# paramAssemblyFileVersion: '3'
37-
# paramAssemblyInformationalVersion: '5'
38-
# paramOverwriteFourthDigitWithBuildCounter: false
39-
# paramVersionCode: '2'
40-
# doAssemblyInfoAppendSuffix: true
41-
# doConvertAssemblyInfoToLowerCase: true
42-
# paramAssemblyInfoSuffixType: '2'
43-
# buildNumberVersionFormat: '3'
44-
# buildNumberAction: 'replace'
45-
# doReplaceAssemblyInfo: false
46-
# doReplaceNuspec: false
47-
# doReplaceNpm: false
48-
# doReplaceDotNetCore: true
49-
# filePatternDotNetCore: '**\*.csproj'
50-
# paramDotNetCoreVersionType: '3'
51-
# doReplaceAndroid: false
52-
# doReplaceiOS: false
53-
# doReplaceCustom: false
54-
# doShowWarningsForUnmatchedRegex: true
55-
# excludeFilePattern: |
56-
# !**/bin/**
57-
# !**/obj/**
5831

59-
#- task: BuildVersioning@0
60-
# condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
61-
# displayName: 'Patching assembly versions (stable build)'
62-
# inputs:
63-
# sourcePath: 'src'
64-
# versionSource: 'gitversion'
65-
# doInstallGitVersion: true
66-
# GitVersionInstallerSource: 'custom'
67-
# GitVersionInstallerUrl: 'https://packages.chocolatey.org/GitVersion.Portable.5.0.1.nupkg'
68-
# doUseLatestGitVersionInstallerVersion: false
69-
# versionFormat: 'fourParts'
70-
# paramAssemblyVersion: '4'
71-
# paramAssemblyFileVersion: '4'
72-
# paramAssemblyInformationalVersion: '4'
73-
# paramVersionCode: '2'
74-
# buildNumberVersionFormat: '3'
75-
# buildNumberAction: 'replace'
76-
# doReplaceAssemblyInfo: false
77-
# doReplaceDotNetCore: true
78-
# filePatternDotNetCore: '**\*.csproj'
79-
# paramDotNetCoreVersionType: '3'
80-
# doShowWarningsForUnmatchedRegex: true
81-
# excludeFilePattern: |
82-
# !**/bin/**
83-
# !**/obj/**
32+
33+
- task: PowerShell@2
34+
displayName: 'Update build number and project version from GitVersion metadata'
35+
inputs:
36+
filePath: azure-pipelines-version.ps1
8437

8538
- task: DotNetCoreCLI@2
8639
displayName: 'Build the solution'

0 commit comments

Comments
 (0)