-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUpdateVersionInfo.ps1
75 lines (60 loc) · 2.77 KB
/
UpdateVersionInfo.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Requires -Version 7.4
# Run this script with pwsh command. Running via .\UpdateVersionInfo.ps1 2024.11.27.356 can't add PackageVersion param somehow
[CmdletBinding()]
param (
# https://regex101.com/r/L80HcG/1
[ValidatePattern("^[0-9]{4}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]+$")]
[String]
$PackageVersion
)
if ($PackageVersion) {
$BuildNumber = $PackageVersion
} else {
# Could be run in DevOps
# The build process will automatically set the value of the BUILD_BUILDNUMBER environment variable to the correct build number
Write-Host "PackageVersion param is empty. Try to set BuildNumber from environment variable"
$BuildNumber = $Env:Build_BuildNumber
}
Write-Host "BuildNumber: $BuildNumber"
if (-not $BuildNumber) {
throw 'BuildNumber variable cannot be null'
}
# Use a regular expression to get "minor, major, fix, revision"
$VersionRegex = "\d+\.\d+\.\*+|\d+\.\d+.\d+\.\d+|\d+\.\d+.\d+"
$NewVersion = [regex]::matches($BuildNumber, $VersionRegex)
Write-Host "Updating version of the application to the build version: $NewVersion"
if (-not $PackageVersion) {
##vso[task.setvariable variable=BUILDNUMBER]$NewVersion
Write-Host "##vso[task.setvariable variable=BUILDNUMBER]$NewVersion"
}
#AssemblyProjectInfo:
$file = ".\AssemblyProjectInfo.cs"
# Search in the "AssemblyProjectInfo.cs" file items that matches the version regex and replace them with the
# correct version number
(Get-Content $file) -replace $VersionRegex, $NewVersion | Out-File $file
$VersionReplaceRegex = "(BUILDVERSION)|(0\.0\.1)"
$VersionRegex = "\d+\.\d+.\d+\.\d+"
$NewVersion = [regex]::matches($BuildNumber, $VersionRegex)
#GDL.IDAS.WebApi.Client.nuspec
$file = ".\Gandalan.IDAS.WebApi.Client\GDL.IDAS.WebApi.Client.nuspec"
# Search in the "GDL.IDAS.WebApi.Client.nuspec" file items that matches the version regex and replace them with the
# correct version number
Write-Host "Updating $file..."
(Get-Content $file) -replace $VersionReplaceRegex, $NewVersion | Out-File $file
#GDL.IDAS.Logging.nuspec
$file = ".\Gandalan.IDAS.Logging\GDL.IDAS.Logging.nuspec"
Write-Host "Updating $file..."
(Get-Content $file) -replace $VersionReplaceRegex, $NewVersion | Out-File $file
#GDL.IDAS.Crypto.nuspec
$file = ".\Gandalan.IDAS.Crypto\GDL.IDAS.Crypto.nuspec"
Write-Host "Updating $file..."
(Get-Content $file) -replace $VersionReplaceRegex, $NewVersion | Out-File $file
#GDL.IDAS.WebApi.Client.Wpf.nuspec
$file = ".\Gandalan.IDAS.WebApi.Client.Wpf\GDL.IDAS.WebApi.Client.Wpf.nuspec"
Write-Host "Updating $file..."
(Get-Content $file) -replace $VersionReplaceRegex, $NewVersion | Out-File $file
#GDL.IDAS.Contracts.nuspec
$file = ".\Gandalan.IDAS.Contracts\GDL.IDAS.Contracts.nuspec"
Write-Host "Updating $file..."
(Get-Content $file) -replace $VersionReplaceRegex, $NewVersion | Out-File $file
Write-Host "Done"