Skip to content

Commit 58468d0

Browse files
committed
GitVersion
- Use GitVersion to stamp version numbers into assemblies. https://github.com/GitTools/GitVersion - Add LibraryVersionInfo class and simple test case.
1 parent 343515a commit 58468d0

7 files changed

Lines changed: 130 additions & 35 deletions

File tree

GitVersion.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
assembly-versioning-scheme: Major
2+
mode: ContinuousDelivery
3+
next-version: 1.1.7
4+
branches: {}
5+
ignore:
6+
sha: []

ServerHost.sln

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27004.2005
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerHost", "ServerHost\ServerHost.csproj", "{98D61E3E-76A7-4664-BAF7-FBBF41A798D9}"
77
EndProject
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1717
Build.sh = Build.sh
1818
Clean.cmd = Clean.cmd
1919
documentation\DocFormatter.xsl = documentation\DocFormatter.xsl
20+
GitVersion.yml = GitVersion.yml
2021
init.cmd = init.cmd
2122
init.ps1 = init.ps1
2223
nuget-restore.cmd = nuget-restore.cmd
@@ -54,4 +55,7 @@ Global
5455
GlobalSection(SolutionProperties) = preSolution
5556
HideSolutionNode = FALSE
5657
EndGlobalSection
58+
GlobalSection(ExtensibilityGlobals) = postSolution
59+
SolutionGuid = {4610FE64-924F-434C-B353-293C0D630539}
60+
EndGlobalSection
5761
EndGlobal

ServerHost/LibraryVersionInfo.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Jorgen Thelin. All rights reserved.
2+
// Licensed with Apache 2.0 https://github.com/jthelin/ServerHost/blob/master/LICENSE
3+
4+
using System.Diagnostics;
5+
using System.Reflection;
6+
7+
namespace Server.Host
8+
{
9+
/// <summary>
10+
/// Version info for ServerHost library.
11+
/// </summary>
12+
/// <remarks>
13+
/// Based on the <c>Orleans.Runtime.RuntimeVersion</c> class.
14+
/// https://github.com/dotnet/orleans/blob/master/src/Orleans/Runtime/RuntimeVersion.cs
15+
/// </remarks>
16+
public static class LibraryVersionInfo
17+
{
18+
private static readonly TypeInfo libraryTypeInfo = typeof(ServerHost).GetTypeInfo();
19+
20+
/// <summary>
21+
/// The full version string of the library.
22+
/// eg: '2012.5.9.51607 Build:12345 Timestamp: 20120509-185359'
23+
/// </summary>
24+
public static string Current
25+
{
26+
get
27+
{
28+
Assembly me = libraryTypeInfo.Assembly;
29+
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(me.Location);
30+
// progVersionInfo.IsDebug; does not work
31+
bool isDebug = IsAssemblyDebugBuild(me);
32+
string productVersion = versionInfo.ProductVersion + (isDebug ? " (Debug)" : " (Release)");
33+
return string.IsNullOrEmpty(productVersion) ? ApiVersion : productVersion;
34+
}
35+
}
36+
37+
/// <summary>
38+
/// The ApiVersion of the library.
39+
/// eg: '1.0.0.0'
40+
/// </summary>
41+
public static string ApiVersion
42+
{
43+
get
44+
{
45+
Assembly me = libraryTypeInfo.Assembly;
46+
AssemblyName libraryInfo = me.GetName();
47+
return libraryInfo.Version.ToString();
48+
}
49+
}
50+
51+
/// <summary>
52+
/// The FileVersion of the library.
53+
/// eg: '2012.5.9.51607'
54+
/// </summary>
55+
public static string FileVersion
56+
{
57+
get
58+
{
59+
Assembly me = libraryTypeInfo.Assembly;
60+
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(me.Location);
61+
string fileVersion = versionInfo.FileVersion;
62+
return string.IsNullOrEmpty(fileVersion) ? ApiVersion : fileVersion;
63+
}
64+
}
65+
66+
private static bool IsAssemblyDebugBuild(Assembly assembly)
67+
{
68+
foreach (object attribute in assembly.GetCustomAttributes(false))
69+
{
70+
DebuggableAttribute debuggableAttribute = attribute as DebuggableAttribute;
71+
if (debuggableAttribute != null)
72+
{
73+
return debuggableAttribute.IsJITTrackingEnabled;
74+
}
75+
}
76+
return false;
77+
}
78+
}
79+
}

ServerHost/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,3 @@
2020

2121
// The following GUID is for the ID of the typelib if this project is exposed to COM
2222
[assembly: Guid("e9fff8d5-f4c0-483d-aee6-5ff82afd434f")]
23-
24-
// Version information for an assembly consists of the following four values:
25-
//
26-
// Major Version
27-
// Minor Version
28-
// Build Number
29-
// Revision
30-
//
31-
// You can specify all the values or you can default the Build and Revision Numbers
32-
// by using the '*' as shown below:
33-
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0.0.0")]

ServerHost/ServerHost.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<ItemGroup>
4848
<Compile Include="Properties\AssemblyInfo.cs" />
4949
<Compile Include="ServerHost.cs" />
50+
<Compile Include="LibraryVersionInfo.cs" />
5051
<Compile Include="ServerHostHandle.cs" />
5152
<Compile Include="ServerHostFixture.cs" />
5253
</ItemGroup>
@@ -77,6 +78,8 @@
7778
</PropertyGroup>
7879
<Error Condition="!Exists('..\packages\GitLink.3.1.0\build\GitLink.props') and '$(OS)' == 'Windows_NT' " Text="$([System.String]::Format('$(ErrorText)', '..\packages\GitLink.3.1.0\build\GitLink.props'))" />
7980
<Error Condition="!Exists('..\packages\GitLink.3.1.0\build\GitLink.targets') and '$(OS)' == 'Windows_NT' " Text="$([System.String]::Format('$(ErrorText)', '..\packages\GitLink.3.1.0\build\GitLink.targets'))" />
81+
<Error Condition="!Exists('..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets'))" />
8082
</Target>
8183
<Import Project="..\packages\GitLink.3.1.0\build\GitLink.targets" Condition="Exists('..\packages\GitLink.3.1.0\build\GitLink.targets') and '$(OS)' == 'Windows_NT' " />
84+
<Import Project="..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets" Condition="Exists('..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets')" />
8285
</Project>

ServerHost/packages.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="GitLink" version="3.1.0" targetFramework="net45" developmentDependency="true" />
4+
<package id="GitVersionTask" version="3.6.5" targetFramework="net45" developmentDependency="true" />
45
<package id="log4net" version="2.0.5" targetFramework="net45" />
5-
</packages>
6+
</packages>

Tests/ServerHostTests.cs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6-
using System.IO;
76
using FluentAssertions;
87
using Xunit;
98
using Xunit.Abstractions;
@@ -15,6 +14,28 @@ public sealed class ServerHostTests : IClassFixture<ServerHostFixture>, IDisposa
1514
private readonly ITestOutputHelper _output;
1615
private readonly string _className;
1716

17+
#region Test Initialization / Cleanup methods
18+
19+
// TestInitialize
20+
public ServerHostTests(ITestOutputHelper output, ServerHostFixture fixture)
21+
{
22+
_output = output;
23+
_className = GetType().Name;
24+
25+
_output.WriteLine("{0} TestInitialize", _className);
26+
_output.WriteLine("{0} Fixture = {1}", _className, fixture);
27+
}
28+
29+
// TestCleanup
30+
public void Dispose()
31+
{
32+
_output.WriteLine("{0} TestCleanup", _className);
33+
34+
_output.WriteLine("{0} UnloadAllServers", _className);
35+
ServerHost.UnloadAllServers();
36+
}
37+
#endregion
38+
1839
[Fact]
1940
[Trait("Category","BVT")]
2041
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
@@ -32,28 +53,22 @@ public void LoadServerInNewAppDomain()
3253
serverHostHandle.Server.Should().BeOfType<TestServer.Server>("Server instance type.");
3354
}
3455

35-
#region Test Initialization / Cleanup methods
36-
37-
// TestInitialize
38-
public ServerHostTests(ITestOutputHelper output, ServerHostFixture fixture)
56+
[Fact]
57+
[Trait("Category", "BVT")]
58+
public void ServerHost_Version()
3959
{
40-
_output = output;
41-
_className = GetType().Name;
42-
output.WriteLine("{0} TestInitialize", _className);
60+
_output.WriteLine("ServerHost library API version = {0}", LibraryVersionInfo.ApiVersion);
61+
_output.WriteLine("ServerHost library file version = {0}", LibraryVersionInfo.FileVersion);
62+
_output.WriteLine("ServerHost library full version info string = {0}", LibraryVersionInfo.Current);
4363

44-
output.WriteLine("{0} Fixture = {1}", _className, fixture);
64+
string versionString = LibraryVersionInfo.FileVersion;
65+
_output.WriteLine("ServerHost library version = {0}", versionString);
4566

46-
output.WriteLine("{0} Current directory = {1}", _className, Directory.GetCurrentDirectory());
47-
}
67+
versionString.Should().NotBeNullOrEmpty("Version value should be returned");
4868

49-
// TestCleanup
50-
public void Dispose()
51-
{
52-
_output.WriteLine("{0} TestCleanup", _className);
53-
54-
_output.WriteLine("{0} UnloadAllServers", _className);
55-
ServerHost.UnloadAllServers();
69+
versionString.Should().Contain(".", "Version format = Major.Minor");
70+
versionString.Should().NotStartWith("1.0.0.0", "Version should be specific.");
71+
versionString.Should().NotStartWith("0.0.0.0", "Version should not be zero.");
5672
}
57-
#endregion
5873
}
5974
}

0 commit comments

Comments
 (0)