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+ # SetVersion.ps1
4+ #
5+ # Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
6+ #
7+ # usage:
8+ # from cmd.exe:
9+ # powershell.exe SetVersion.ps1 2.8.3.0
10+ #
11+ # from powershell.exe prompt:
12+ # .\SetVersion.ps1 2.8.3.0
13+ #
14+ # last saved Time-stamp: <Wednesday, April 23, 2008 11:46:40 (by dinoch)>
15+ #
16+
17+
18+ function Usage
19+ {
20+ echo " Usage: " ;
21+ echo " from cmd.exe: " ;
22+ echo " powershell.exe SetVersion.ps1 2.8.3.0" ;
23+ echo " " ;
24+ echo " from powershell.exe prompt: " ;
25+ echo " .\SetVersion.ps1 2.8.3.0" ;
26+ echo " " ;
27+ }
28+
29+
30+ function Update-SourceVersion
31+ {
32+ Param ([string ]$Version )
33+ $NewVersion = ' AssemblyVersion("' + $Version + ' ")' ;
34+ $NewFileVersion = ' AssemblyFileVersion("' + $Version + ' ")' ;
35+
36+ foreach ($o in $input )
37+ {
38+ Write-output $o.FullName
39+ $TmpFile = $o.FullName + " .tmp"
40+
41+ Get-Content $o.FullName - encoding utf8 |
42+ % {$_ -replace ' AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' , $NewVersion } |
43+ % {$_ -replace ' AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' , $NewFileVersion } |
44+ Set-Content $TmpFile - encoding utf8
45+
46+ move-item $TmpFile $o.FullName - force
47+ }
48+ }
49+
50+
51+ function Update-AllAssemblyInfoFiles ( $version )
52+ {
53+ foreach ($file in " AssemblyInfo.cs" , " AssemblyInfo.vb" )
54+ {
55+ get-childitem - recurse | ? {$_.Name -eq $file } | Update-SourceVersion $version ;
56+ }
57+ }
58+
59+
60+ # validate arguments
61+ $r = [System.Text.RegularExpressions.Regex ]::Match($args [0 ], " ^[0-9]+(\.[0-9]+){1,3}$" );
62+
63+ if ($r.Success )
64+ {
65+ Update-AllAssemblyInfoFiles $args [0 ];
66+ }
67+ else
68+ {
69+ echo " " ;
70+ echo " Bad Input!"
71+ echo " " ;
72+ Usage ;
73+ }
0 commit comments