-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifyVersion.ps1
More file actions
49 lines (37 loc) · 1.51 KB
/
ModifyVersion.ps1
File metadata and controls
49 lines (37 loc) · 1.51 KB
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
Param($projectFile, $buildNum)
# Modified from https://blog.johnnyreilly.com/2017/04/setting-build-version-using-appveyor.html
$content = [IO.File]::ReadAllText($projectFile)
$regex = new-object System.Text.RegularExpressions.Regex (
'(([\d]+.[\d]+.[\d])(-[a-zA-Z\.\-0-9]*)?)<\/Version>',
[System.Text.RegularExpressions.RegexOptions]::MultiLine)
$version = $null
$match = $regex.Match($content)
echo $match
if(!$match.Success) { throw 'No version found' }
$version = $match.groups[1].value
echo "version = $version"
$numericPartOfVersion = $match.groups[2].value
echo "numericPartOfVersion = $numericPartOfVersion"
$fileVersion = "$numericPartOfVersion.$buildNum"
echo "fileVersion = $fileVersion"
if ([string]::IsNullOrEmpty($match.groups[3]))
{
# found a release indicator
# append buildNum and timestamp to the version as metadata
$buildTimestamp = (Get-Date).ToUniversalTime().ToString("yyyyMMddTHHmmssfffffffZ")
$version = "$version+build.$buildNum-$buildTimestamp"
echo "release version detected: updated with buildNum to $version"
}
else
{
# found a pre-release indicator
# append buildNum to the pre-release portion of the version
$version = "$version-build.$buildNum"
echo "pre-release version detected: updated with buildNum to $version"
}
$content = $regex.Replace($content, "$version</Version><FileVersion>$fileVersion</FileVersion>")
# update csproj file
[IO.File]::WriteAllText($projectFile, $content)
echo "updating AppVeyor version"
# update AppVeyor build
Update-AppveyorBuild -Version $version