Skip to content

Commit 38f2057

Browse files
authored
Create ChangeVersion.ps1
1 parent 1319489 commit 38f2057

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

ChangeVersion.ps1

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# from http://blogs.msdn.com/b/dotnetinterop/archive/2008/04/21/powershell-script-to-batch-update-assemblyinfo-cs-with-new-version.aspx
2+
3+
function Update-SourceVersion
4+
{
5+
Param ([string]$Version)
6+
$NewVersion = 'AssemblyVersion("' + $Version + '")';
7+
$NewFileVersion = 'AssemblyFileVersion("' + $Version + '")';
8+
9+
foreach ($o in $input)
10+
{
11+
Write-output $o.FullName
12+
$TmpFile = $o.FullName + ".tmp"
13+
14+
Get-Content $o.FullName -encoding utf8 |
15+
%{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
16+
%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } |
17+
Set-Content $TmpFile -encoding utf8
18+
19+
move-item $TmpFile $o.FullName -force
20+
}
21+
}
22+
23+
24+
function Update-AllAssemblyInfoFiles ( $version )
25+
{
26+
foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" )
27+
{
28+
get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;
29+
}
30+
}
31+
32+
33+
# validate arguments
34+
$r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");
35+
36+
if ($r.Success)
37+
{
38+
Update-AllAssemblyInfoFiles $args[0];
39+
}
40+
else
41+
{
42+
echo " ";
43+
echo "Bad Input!"
44+
echo " ";
45+
Usage ;
46+
}

0 commit comments

Comments
 (0)