-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetVersion.ps1
More file actions
52 lines (45 loc) · 1.25 KB
/
SetVersion.ps1
File metadata and controls
52 lines (45 loc) · 1.25 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
50
51
52
# SetVersion.ps1
#
# Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
#
# Usage:
# . ./SetVersion.ps1
# SetVersion $version $folder
# SetVersion $version
function global:SetVersion($directory, $version)
{
# validate arguments
$r = [System.Text.RegularExpressions.Regex]::Match($version, "^[0-9]+(\.[0-9]+){1,3}$")
if ($r.Success)
{
if(Test-Path $directory)
{
_SearchAndUpdateInfoFiles $directory $version
}
}
else
{
throw "Invalid version format";
}
}
function _SearchAndUpdateInfoFiles($directory, $version)
{
foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" )
{
get-childitem -path $directory -recurse |? {$_.Name -eq $file} | _UpdateFileVersion $file $version
}
}
function _UpdateFileVersion($input, $version)
{
$NewVersion = 'AssemblyVersion("' + $version + '")'
$NewFileVersion = 'AssemblyFileVersion("' + $version + '")'
foreach ($o in $input)
{
Write-output $o.FullName
$TmpFile = $o.FullName + ".tmp"
get-content $o.FullName |
%{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } > $TmpFile
move-item $TmpFile $o.FullName -force
}
}