-
Notifications
You must be signed in to change notification settings - Fork 0
/
IncrementVersion.ps1
67 lines (62 loc) · 2.03 KB
/
IncrementVersion.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
function IncrementVersion-InAllAssemblyInfoFiles($rank)
{
dir -Include AssemblyInfoCommon.cs -Recurse |
% { IncrementVersion-InFile $_ $rank }
dir -Include *.nuspec -Recurse |
% { IncrementVersion-NuSpec $_ $rank }
}
function IncrementVersion-InFile($file, $rank)
{
switch ($rank)
{
'major' { $exp = ([regex]'(^\s*\[assembly:\s*Assembly.*Version\s*\(\s*)"(\d+\.\d+\.\d+\.\d+)"(\s*\)\s*]\s*$)') }
default { $exp = ([regex]'(^\s*\[assembly:\s*AssemblyFileVersion\s*\(\s*)"(\d+\.\d+\.\d+\.\d+)"(\s*\)\s*]\s*$)') }
}
(Get-Content $file) |
% {
$match = $exp.match($_)
if ($match.success)
{
$ov = New-Object Version($match.groups[2].value)
$nv = Increment-Version $ov $rank
$replaced = $exp.replace($_, '$1"' + $nv + '"$3')
$replaced
}
else
{
$_
}
} |
Set-Content $file -encoding UTF8
}
function IncrementVersion-NuSpec($file, $rank)
{
(Get-Content $file) |
% {
$exp = ([regex]'(^\s*<version>)(\d+\.\d+\.\d+)(</version>\s*$)')
$match = $exp.match($_)
if ($match.success)
{
$ov = New-Object Version($match.groups[2].value + '.0')
$nv = Increment-Version $ov $rank
$replaced = $exp.replace($_, $match.groups[1].value + $nv.Major + '.' + $nv.Minor + '.' + $nv.Build + $match.groups[3].value)
$replaced
}
else
{
$_
}
} |
Set-Content $file -encoding ASCII
}
function Increment-Version($version, $rank)
{
switch ($rank)
{
'major' { New-Object Version(($version.Major + 1), 0, 0, 0) }
'minor' { New-Object Version($version.Major, ($version.Minor + 1), 0, 0) }
default { New-Object Version($version.Major, $version.Minor, ($version.Build + 1), $version.Revision) }
'revision' { New-Object Version($version.Major, $version.Minor, $version.Build, ($version.Revision +1 )) }
}
}
IncrementVersion-InAllAssemblyInfoFiles $args[0]