-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
6 changed files
with
102 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="GitVersionTask" version="3.6.5" targetFramework="net45" developmentDependency="true" /> | ||
<package id="log4net" version="2.0.5" targetFramework="net45" /> | ||
<package id="SourceLink.Create.CommandLine" version="2.5.0" targetFramework="net45" developmentDependency="true" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters