forked from HearthSim/Hearthstone-Deck-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_version.ps1
42 lines (34 loc) · 1.45 KB
/
update_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
37
38
39
40
41
42
Param(
[Parameter(Mandatory=$True)]
[int]$buildNumber,
[Parameter(Mandatory=$True)]
[boolean]$dev
)
$baseDir = $(Resolve-Path "$PSScriptRoot\..").Path
$projectFile = "$baseDir\Hearthstone Deck Tracker\Hearthstone Deck Tracker.csproj"
# Read version number from AssemblyInfo
$assemblyInfo = [IO.File]::ReadAllText($projectFile)
$assemblyVersionRegex = New-Object System.Text.RegularExpressions.Regex('<AssemblyVersion>(\d+)\.(\d+)\.(\d+)</AssemblyVersion>')
$match = $assemblyVersionRegex.Match($assemblyInfo)
if(!$match.Success) {
throw "AssemblyVersion not found in csproj"
}
$major = $match.Groups[1].Value
$minor = $match.Groups[2].Value
$patch = $match.Groups[3].Value
# Construct package version
if ($dev) {
$patch = [int]$patch + 1
}
$packageVersion = "$major.$minor.$patch"
if ($dev) {
$packageVersion = "$packageVersion-dev$buildNumber"
}
# Update AssemblyInfo.cs with the new version
$assemblyVersion = "$major.$minor.$patch.$buildNumber"
$assemblyInfo = $assemblyVersionRegex.Replace($assemblyInfo, '<AssemblyVersion>' + $assemblyVersion + '</AssemblyVersion>')
$fileVersionRegex = New-Object System.Text.RegularExpressions.Regex('<FileVersion>.*</FileVersion>')
$assemblyInfo = $fileVersionRegex.Replace($assemblyInfo, '<FileVersion>' + $assemblyVersion + '</FileVersion>')
[IO.File]::WriteAllText($projectFile, $assemblyInfo)
Write-Host "AssemblyVersion=$assemblyVersion, PackageVersion=$packageVersion"
Write-Output $packageVersion