1+ param (
2+ [string ]$path = " c:\Users\$ ( $env: username ) \desktop\AssemblyInfo.cs" ,
3+ [int ]$major = 1 ,
4+ [int ]$minor = 0
5+ )
6+
7+ # $file = Get-Content $path | Out-String
8+ $file = [System.IO.File ]::ReadAllText( $path )
9+
10+ # adjust AssemblyVersion
11+ $pattern = ' AssemblyVersion\( \"(?<v>\d.\d.\d.\d)\" \)'
12+ $vers = ([regex ]::Match( $file , $pattern )).Groups
13+ [Version ]$version = [Version ]$vers.Groups [1 ].Value
14+ $v = ' AssemblyVersion( "{0}.{1}.{2}.{3}" )' -f $major , $minor , $version.Build , $version.Revision
15+ $file = ([regex ]::Replace( $file , $pattern , $v ))
16+
17+
18+ # adjust AssemblyFileVersion
19+ $pattern = ' AssemblyFileVersion\( \"(?<v>.*)\" \)'
20+ $vers = ([regex ]::Match( $file , $pattern )).Groups
21+ [Version ]$version = [Version ]$vers.Groups [1 ].Value
22+
23+ $now = [DateTime ]::Now
24+ $build = ' {0}{1}' -f $now.ToString ( ' yy' ), $now.DayOfYear.ToString ( ' D3' )
25+ [int ]$revision = [int ]$version.Revision
26+ if ( $version.Build.ToString () -eq $build )
27+ {
28+ $revision = [int ]$version.Revision + 1
29+ }
30+
31+ $v = ' AssemblyFileVersion( "{0}.{1}.{2}.{3}" )' -f $major , $minor , $build , $revision
32+ $file = ([regex ]::Replace( $file , $pattern , $v ))
33+
34+ Write-Host $file
35+ [System.IO.File ]::SetAttributes( $path , [System.IO.FileAttributes ]::Normal );
36+ [System.IO.File ]::WriteAllText( $path , $file )
37+ # Set-Content -Path $path -Value $file.Trim()
0 commit comments