Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit 75f1710

Browse files
committed
SetVersion module
1 parent d547789 commit 75f1710

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tools/SetVersion.psm1

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# SetVersion.ps1
2+
#
3+
# Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
4+
#
5+
# usage:
6+
# from cmd.exe:
7+
# powershell.exe SetVersion.ps1 2.8.3.0
8+
#
9+
# from powershell.exe prompt:
10+
# .\SetVersion.ps1 2.8.3.0
11+
#
12+
# last saved Time-stamp: <Wednesday, April 23, 2008 11:46:40 (by dinoch)>
13+
#
14+
15+
16+
function Usage
17+
{
18+
echo "Usage: ";
19+
echo " from cmd.exe: ";
20+
echo " powershell.exe SetVersion.ps1 2.8.3.0";
21+
echo " ";
22+
echo " from powershell.exe prompt: ";
23+
echo " .\SetVersion.ps1 2.8.3.0";
24+
echo " ";
25+
}
26+
27+
28+
function Update-SourceVersion
29+
{
30+
Param ([string]$Version)
31+
$NewVersion = 'AssemblyVersion("' + $Version + '")';
32+
$FileVersion = $Version;
33+
if($FileVersion.EndsWith(".*"))
34+
{
35+
$FileVersion = $FileVersion.Replace(".*", "")
36+
}
37+
38+
$NewFileVersion = 'AssemblyFileVersion("' + $FileVersion + '")';
39+
40+
foreach ($o in $input)
41+
{
42+
Write-output $o.FullName
43+
$TmpFile = $o.FullName + ".tmp"
44+
45+
$NewContents = get-content $o.FullName |
46+
%{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
47+
%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } # > $TmpFile
48+
49+
$NewContents | out-file $o.FullName
50+
#move-item $TmpFile $o.FullName -force
51+
}
52+
}
53+
54+
55+
function Update-AllAssemblyInfoFiles ( $version )
56+
{
57+
foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" )
58+
{
59+
get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;
60+
}
61+
}
62+
63+
function Set-Version
64+
{
65+
Param ([string]$Version)
66+
# validate arguments
67+
$r= [System.Text.RegularExpressions.Regex]::Match($Version, "^[0-9]+(\.[0-9]+){1,3}(\.\*)?$");
68+
69+
if ($r.Success)
70+
{
71+
Update-AllAssemblyInfoFiles $Version;
72+
}
73+
else
74+
{
75+
echo " ";
76+
echo "Bad Input!";
77+
echo " ";
78+
Usage ;
79+
80+
Write-Error "Failed To Set Version"
81+
}
82+
}
83+
84+
export-modulemember -function Set-Version -variable Version

0 commit comments

Comments
 (0)