forked from moodmosaic/Fare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IncrementVersion.ps1
39 lines (36 loc) · 2.45 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
function IncrementVersion-InAllAssemblyInfoFiles($rank)
{
dir -Include AssemblyInfo.cs -Recurse |
% { IncrementVersion-InFile $_ $rank }
}
function IncrementVersion-InFile($file, $rank)
{
(Get-Content $file) |
% {
$exp = ([regex]'(^\s*\[assembly:\s*Assembly.*Version\s*\(\s*)"(\d+\.\d+\.\d+\.\d+)"(\s*\)\s*]\s*$)')
$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 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]