Skip to content

Commit

Permalink
Get version number from GitVersion
Browse files Browse the repository at this point in the history
- use GitVersion version number in About dialog
- refactor getting version
  • Loading branch information
ermshiperete committed Jul 8, 2016
1 parent ea831a4 commit e27818e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions BuildDependencyLib/BuildDependencyLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="TeamCity\RestClasses\Property.cs" />
<Compile Include="Tools\ExceptionLogging.cs" />
<Compile Include="Tools\Platform.cs" />
<Compile Include="Tools\Utils.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\GitVersionTask.4.0.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets" Condition="Exists('..\packages\GitVersionTask.4.0.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" />
Expand Down
25 changes: 25 additions & 0 deletions BuildDependencyLib/Tools/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2016 SIL International
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
using System;
using System.Reflection;

namespace BuildDependency.Tools
{
public static class Utils
{
public static Tuple<object, string> GetVersion(string ns)
{
// Access fields in GitVersionInformation that GitVersion creates at compile time
var gitVersionInformationType = Assembly.GetCallingAssembly()
.GetType(ns + ".GitVersionInformation");
if (gitVersionInformationType == null)
return new Tuple<object, string>(null, string.Empty);
var fullSemVer = gitVersionInformationType.GetField("FullSemVer");
var sha = gitVersionInformationType.GetField("Sha");
return new Tuple<object, string>(fullSemVer.GetValue(null),
sha.GetValue(null).ToString().Substring(0, 7));
}

}
}

7 changes: 5 additions & 2 deletions BuildDependencyManager/Dialogs/AboutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)
using System;
using System.Reflection;
using BuildDependency.Tools;
using Eto.Drawing;
using Eto.Forms;

Expand Down Expand Up @@ -31,9 +32,11 @@ public AboutDialog()

var labelVersion = new Label();
labelVersion.TextAlignment = TextAlignment.Center;
labelVersion.Text = string.Format("{0}{1}", Assembly.GetExecutingAssembly().GetName().Version,

var version = Utils.GetVersion("BuildDependency.Manager");
labelVersion.Text = string.Format("{0} ({1}){2}", version.Item1, version.Item2,
#if DEBUG
" (Debug)"
" - Debug"
#else
""
#endif
Expand Down
20 changes: 3 additions & 17 deletions BuildDependencyTasks/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using BuildDependency.Artifacts;
using BuildDependency.Tasks.Tools;
Expand Down Expand Up @@ -77,20 +76,6 @@ public bool RunAsync
public bool KeepJobsFile
{ get; set; }

private Tuple<object, string> Version
{
get
{
// Access fields in GitVersionInformation that GitVersion creates at compile time
var gitVersionInformationType = Assembly.GetExecutingAssembly()
.GetType("BuildDependency.Tasks.GitVersionInformation");
var fullSemVer = gitVersionInformationType.GetField("FullSemVer");
var sha = gitVersionInformationType.GetField("Sha");
return new Tuple<object, string>(fullSemVer.GetValue(null),
sha.GetValue(null).ToString());
}
}

public override bool Execute()
{
ILog logHelper;
Expand All @@ -99,8 +84,9 @@ public override bool Execute()
else
logHelper = new LogHelper();

logHelper.LogMessage("Dependencies task version {0} ({1}):", Version.Item1,
Version.Item2.Substring(0, 7));
var version = Utils.GetVersion("BuildDependency.Tasks");
logHelper.LogMessage("Dependencies task version {0} ({1}):", version.Item1,
version.Item2);

if (UseDependencyFile && string.IsNullOrEmpty(DependencyFile))
{
Expand Down

0 comments on commit e27818e

Please sign in to comment.