|
1 | 1 | param ( |
2 | | - [string]$path, # = "c:\Users\$($env:username)\desktop\AssemblyInfo.cs", |
3 | | - [int]$major = 1, |
4 | | - [int]$minor = 0 |
| 2 | + [string]$path, #= "c:\Users\$($env:username)\desktop\AssemblyInfo.cs", |
| 3 | + [int]$major = 0, |
| 4 | + [int]$minor = 1, |
| 5 | + [string]$versionFile #= "c:\Users\$($env:username)\desktop\AssemblyInfo.xml" |
5 | 6 | ) |
6 | 7 |
|
7 | | -$file = [System.IO.File]::ReadAllText( $path ) |
| 8 | +$now = [DateTime]::Now |
| 9 | +$avp = 'AssemblyVersion\( \"(?<v>\d.\d.\d.\d)\" \)' |
| 10 | +$afvp = 'AssemblyFileVersion\( \"(?<v>.*)\" \)' |
8 | 11 |
|
9 | | -#adjust AssemblyVersion |
10 | | -$pattern = 'AssemblyVersion\( \"(?<v>\d.\d.\d.\d)\" \)' |
11 | | -$vers = ([regex]::Match( $file, $pattern )).Groups |
12 | | -[Version]$version = [Version]$vers.Groups[1].Value |
13 | | -$v = 'AssemblyVersion( "{0}.{1}.{2}.{3}" )' -f $major, $minor, $version.Build, $version.Revision |
14 | | -$file = ([regex]::Replace( $file, $pattern, $v )) |
| 12 | +$file = [System.IO.File]::ReadAllText( $path ) |
15 | 13 |
|
| 14 | +if( [System.IO.File]::Exists( $versionFile ) ) |
| 15 | +{ |
| 16 | + [Xml]$vf = Get-Content $versionFile |
16 | 17 |
|
17 | | -#adjust AssemblyFileVersion |
18 | | -$pattern = 'AssemblyFileVersion\( \"(?<v>.*)\" \)' |
19 | | -$vers = ([regex]::Match( $file, $pattern )).Groups |
20 | | -[Version]$version = [Version]$vers.Groups[1].Value |
| 18 | + #adjust AssemblyVersion |
| 19 | + $v = 'AssemblyVersion( "{0}.{1}.{2}.{3}" )' -f $vf.ai.av.Major, $vf.ai.av.Minor, $vf.ai.av.Build, $vf.ai.av.Revision |
| 20 | + $file = ([regex]::Replace( $file, $avp, $v )) |
21 | 21 |
|
22 | | -$now = [DateTime]::Now |
23 | | -$build = '{0}{1}' -f $now.ToString( 'yy' ), $now.DayOfYear.ToString( 'D3' ) |
24 | | -[int]$revision = [int]$version.Revision |
25 | | -if( $version.Build.ToString() -eq $build ) |
26 | | -{ |
27 | | - $revision = [int]$version.Revision + 1 |
| 22 | + #adjust AssemblyFileVersion |
| 23 | + if( $vf.ai.afv.Build.ToString() -eq '#' ) |
| 24 | + { |
| 25 | + $vf.ai.afv.Build = '{0}{1}' -f $now.ToString( 'yy' ), $now.DayOfYear.ToString( 'D3' ) |
| 26 | + } |
| 27 | + $v = 'AssemblyFileVersion( "{0}.{1}.{2}.{3}" )' -f $vf.ai.afv.Major, $vf.ai.afv.Minor, $vf.ai.afv.Build, $vf.ai.afv.Revision |
| 28 | + $file = ([regex]::Replace( $file, $afvp, $v )) |
28 | 29 | } |
| 30 | +else |
| 31 | +{ |
| 32 | + #adjust AssemblyVersion |
| 33 | + $vers = ([regex]::Match( $file, $avp )).Groups |
| 34 | + [Version]$version = [Version]$vers.Groups[1].Value |
| 35 | + $v = 'AssemblyVersion( "{0}.{1}.{2}.{3}" )' -f $major, $minor, $version.Build, $version.Revision |
| 36 | + $file = ([regex]::Replace( $file, $avp, $v )) |
29 | 37 |
|
30 | | -$v = 'AssemblyFileVersion( "{0}.{1}.{2}.{3}" )' -f $major, $minor, $build, $revision |
31 | | -$file = ([regex]::Replace( $file, $pattern, $v )) |
32 | 38 |
|
33 | | -Write-Host $file |
| 39 | + #adjust AssemblyFileVersion |
| 40 | + $vers = ([regex]::Match( $file, $afvp )).Groups |
| 41 | + [Version]$version = [Version]$vers.Groups[1].Value |
| 42 | + |
| 43 | + $build = '{0}{1}' -f $now.ToString( 'yy' ), $now.DayOfYear.ToString( 'D3' ) |
| 44 | + [int]$revision = 1 |
| 45 | + if( $version.Build.ToString() -eq $build ) |
| 46 | + { |
| 47 | + $revision = [int]$version.Revision + 1 |
| 48 | + } |
| 49 | + |
| 50 | + $v = 'AssemblyFileVersion( "{0}.{1}.{2}.{3}" )' -f $major, $minor, $build, $revision |
| 51 | + $file = ([regex]::Replace( $file, $afvp, $v )) |
| 52 | +} |
| 53 | + |
| 54 | +#Write-Host $file |
34 | 55 | [System.IO.File]::SetAttributes( $path, [System.IO.FileAttributes]::Normal ); |
35 | 56 | [System.IO.File]::WriteAllText( $path, $file ) |
0 commit comments