Skip to content

Commit

Permalink
GitVersion
Browse files Browse the repository at this point in the history
- Use GitVersion to stamp version numbers into assemblies.

https://github.com/GitTools/GitVersion

- Add LibraryVersionInfo class and simple test case.

GitVersion mode = ContinuousDelivery

- `Mainline` mode is not available until GitVersion v4.x [currently in pre-release]
  • Loading branch information
jthelin committed Oct 25, 2017
1 parent 44abec0 commit 7c0d656
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 35 deletions.
8 changes: 6 additions & 2 deletions ServerHost.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerHost", "ServerHost\ServerHost.csproj", "{98D61E3E-76A7-4664-BAF7-FBBF41A798D9}"
EndProject
Expand All @@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Build.sh = Build.sh
Clean.cmd = Clean.cmd
documentation\DocFormatter.xsl = documentation\DocFormatter.xsl
GitVersion.yml = GitVersion.yml
init.cmd = init.cmd
init.ps1 = init.ps1
nuget-restore.cmd = nuget-restore.cmd
Expand Down Expand Up @@ -54,4 +55,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4610FE64-924F-434C-B353-293C0D630539}
EndGlobalSection
EndGlobal
79 changes: 79 additions & 0 deletions ServerHost/LibraryVersionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Jorgen Thelin. All rights reserved.
// Licensed with Apache 2.0 https://github.com/jthelin/ServerHost/blob/master/LICENSE

using System.Diagnostics;
using System.Reflection;

namespace Server.Host
{
/// <summary>
/// Version info for ServerHost library.
/// </summary>
/// <remarks>
/// Based on the <c>Orleans.Runtime.RuntimeVersion</c> class.
/// https://github.com/dotnet/orleans/blob/master/src/Orleans/Runtime/RuntimeVersion.cs
/// </remarks>
public static class LibraryVersionInfo
{
private static readonly TypeInfo libraryTypeInfo = typeof(ServerHost).GetTypeInfo();

/// <summary>
/// The full version string of the library.
/// eg: '2012.5.9.51607 Build:12345 Timestamp: 20120509-185359'
/// </summary>
public static string Current
{
get
{
Assembly me = libraryTypeInfo.Assembly;
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(me.Location);
// progVersionInfo.IsDebug; does not work
bool isDebug = IsAssemblyDebugBuild(me);
string productVersion = versionInfo.ProductVersion + (isDebug ? " (Debug)" : " (Release)");
return string.IsNullOrEmpty(productVersion) ? ApiVersion : productVersion;
}
}

/// <summary>
/// The ApiVersion of the library.
/// eg: '1.0.0.0'
/// </summary>
public static string ApiVersion
{
get
{
Assembly me = libraryTypeInfo.Assembly;
AssemblyName libraryInfo = me.GetName();
return libraryInfo.Version.ToString();
}
}

/// <summary>
/// The FileVersion of the library.
/// eg: '2012.5.9.51607'
/// </summary>
public static string FileVersion
{
get
{
Assembly me = libraryTypeInfo.Assembly;
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(me.Location);
string fileVersion = versionInfo.FileVersion;
return string.IsNullOrEmpty(fileVersion) ? ApiVersion : fileVersion;
}
}

private static bool IsAssemblyDebugBuild(Assembly assembly)
{
foreach (object attribute in assembly.GetCustomAttributes(false))
{
DebuggableAttribute debuggableAttribute = attribute as DebuggableAttribute;
if (debuggableAttribute != null)
{
return debuggableAttribute.IsJITTrackingEnabled;
}
}
return false;
}
}
}
13 changes: 0 additions & 13 deletions ServerHost/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,3 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e9fff8d5-f4c0-483d-aee6-5ff82afd434f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3 changes: 3 additions & 0 deletions ServerHost/ServerHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerHost.cs" />
<Compile Include="LibraryVersionInfo.cs" />
<Compile Include="ServerHostHandle.cs" />
<Compile Include="ServerHostFixture.cs" />
</ItemGroup>
Expand Down Expand Up @@ -77,6 +78,8 @@
</PropertyGroup>
<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'))" />
<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'))" />
<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'))" />
</Target>
<Import Project="..\packages\GitLink.3.1.0\build\GitLink.targets" Condition="Exists('..\packages\GitLink.3.1.0\build\GitLink.targets') and '$(OS)' == 'Windows_NT' " />
<Import Project="..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets" Condition="Exists('..\packages\GitVersionTask.3.6.5\build\dotnet\GitVersionTask.targets')" />
</Project>
3 changes: 2 additions & 1 deletion ServerHost/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GitLink" version="3.1.0" targetFramework="net45" developmentDependency="true" />
<package id="GitVersionTask" version="3.6.5" targetFramework="net45" developmentDependency="true" />
<package id="log4net" version="2.0.5" targetFramework="net45" />
</packages>
</packages>
53 changes: 34 additions & 19 deletions Tests/ServerHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -15,6 +14,28 @@ public sealed class ServerHostTests : IClassFixture<ServerHostFixture>, IDisposa
private readonly ITestOutputHelper _output;
private readonly string _className;

#region Test Initialization / Cleanup methods

// TestInitialize
public ServerHostTests(ITestOutputHelper output, ServerHostFixture fixture)
{
_output = output;
_className = GetType().Name;

_output.WriteLine("{0} TestInitialize", _className);
_output.WriteLine("{0} Fixture = {1}", _className, fixture);
}

// TestCleanup
public void Dispose()
{
_output.WriteLine("{0} TestCleanup", _className);

_output.WriteLine("{0} UnloadAllServers", _className);
ServerHost.UnloadAllServers();
}
#endregion

[Fact]
[Trait("Category","BVT")]
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
Expand All @@ -32,28 +53,22 @@ public void LoadServerInNewAppDomain()
serverHostHandle.Server.Should().BeOfType<TestServer.Server>("Server instance type.");
}

#region Test Initialization / Cleanup methods

// TestInitialize
public ServerHostTests(ITestOutputHelper output, ServerHostFixture fixture)
[Fact]
[Trait("Category", "BVT")]
public void ServerHost_Version()
{
_output = output;
_className = GetType().Name;
output.WriteLine("{0} TestInitialize", _className);
_output.WriteLine("ServerHost library API version = {0}", LibraryVersionInfo.ApiVersion);
_output.WriteLine("ServerHost library file version = {0}", LibraryVersionInfo.FileVersion);
_output.WriteLine("ServerHost library full version info string = {0}", LibraryVersionInfo.Current);

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

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

// TestCleanup
public void Dispose()
{
_output.WriteLine("{0} TestCleanup", _className);

_output.WriteLine("{0} UnloadAllServers", _className);
ServerHost.UnloadAllServers();
versionString.Should().Contain(".", "Version format = Major.Minor");
versionString.Should().NotStartWith("1.0.0.0", "Version should be specific.");
versionString.Should().NotStartWith("0.0.0.0", "Version should not be zero.");
}
#endregion
}
}

0 comments on commit 7c0d656

Please sign in to comment.