Skip to content

Commit 760f607

Browse files
committed
update to setVersion script to support setting fixed version when required
1 parent a220b21 commit 760f607

6 files changed

Lines changed: 62 additions & 27 deletions

File tree

Synapse.NodeService.HttpClient/Synapse.NodeService.HttpClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</ItemGroup>
5454
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5555
<PropertyGroup>
56-
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)scripts\setVersion.ps1 -path $(ProjectDir)Properties\AssemblyInfo.cs -major 0 -minor 1</PreBuildEvent>
56+
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)scripts\setVersion.ps1 -path $(ProjectDir)Properties\AssemblyInfo.cs -versionFile $(SolutionDir)scripts\AssemblyInfo.xml</PreBuildEvent>
5757
</PropertyGroup>
5858
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
5959
Other similar extension points exist, see Microsoft.Common.targets.

Synapse.NodeService.cli/Synapse.NodeService.cli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</ItemGroup>
7777
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7878
<PropertyGroup>
79-
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)scripts\setVersion.ps1 -path $(ProjectDir)Properties\AssemblyInfo.cs -major 0 -minor 1</PreBuildEvent>
79+
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)scripts\setVersion.ps1 -path $(ProjectDir)Properties\AssemblyInfo.cs -versionFile $(SolutionDir)scripts\AssemblyInfo.xml</PreBuildEvent>
8080
</PropertyGroup>
8181
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8282
Other similar extension points exist, see Microsoft.Common.targets.

Synapse.NodeService/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
// by using the '*' as shown below:
3636
// [assembly: AssemblyVersion("1.0.*")]
3737
[assembly: AssemblyVersion( "0.1.0.0" )]
38-
[assembly: AssemblyFileVersion( "0.1.17034.2" )]
38+
[assembly: AssemblyFileVersion( "0.1.17035.1" )]

Synapse.NodeService/Synapse.NodeService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
</ItemGroup>
9393
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
9494
<PropertyGroup>
95-
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)scripts\setVersion.ps1 -path $(ProjectDir)Properties\AssemblyInfo.cs -major 0 -minor 1</PreBuildEvent>
95+
<PreBuildEvent>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File $(SolutionDir)scripts\setVersion.ps1 -path $(ProjectDir)Properties\AssemblyInfo.cs -versionFile $(SolutionDir)scripts\AssemblyInfo.xml</PreBuildEvent>
9696
</PropertyGroup>
9797
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
9898
Other similar extension points exist, see Microsoft.Common.targets.

scripts/AssemblyInfo.xml_x

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<ai>
2+
<av>
3+
<Major>0</Major>
4+
<Minor>1</Minor>
5+
<Build>0</Build>
6+
<Revision>0</Revision>
7+
</av>
8+
<afv>
9+
<Major>0</Major>
10+
<Minor>1</Minor>
11+
<Build>#</Build>
12+
<Revision>0</Revision>
13+
</afv>
14+
</ai>

scripts/setVersion.ps1

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
11
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"
56
)
67

7-
$file = [System.IO.File]::ReadAllText( $path )
8+
$now = [DateTime]::Now
9+
$avp = 'AssemblyVersion\( \"(?<v>\d.\d.\d.\d)\" \)'
10+
$afvp = 'AssemblyFileVersion\( \"(?<v>.*)\" \)'
811

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 )
1513

14+
if( [System.IO.File]::Exists( $versionFile ) )
15+
{
16+
[Xml]$vf = Get-Content $versionFile
1617

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 ))
2121

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 ))
2829
}
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 ))
2937

30-
$v = 'AssemblyFileVersion( "{0}.{1}.{2}.{3}" )' -f $major, $minor, $build, $revision
31-
$file = ([regex]::Replace( $file, $pattern, $v ))
3238

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
3455
[System.IO.File]::SetAttributes( $path, [System.IO.FileAttributes]::Normal );
3556
[System.IO.File]::WriteAllText( $path, $file )

0 commit comments

Comments
 (0)