Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created February 4, 2012 00:39
Show Gist options
  • Save anaisbetts/1734073 to your computer and use it in GitHub Desktop.
Save anaisbetts/1734073 to your computer and use it in GitHub Desktop.
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
using System;
using System.Windows;
<#
var pathEntries = System.Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator);
FileInfo gitFileInfo = null;
foreach(var item in pathEntries) {
var fi = new FileInfo(Path.Combine(item, "git.cmd"));
if (fi.Exists) {
gitFileInfo = fi;
break;
}
}
var psi = new System.Diagnostics.ProcessStartInfo(gitFileInfo.FullName, "show-ref HEAD") {
WorkingDirectory = Host.ResolvePath(""),
RedirectStandardOutput = true,
CreateNoWindow = true,
UseShellExecute = false,
};
var proc = System.Diagnostics.Process.Start(psi);
proc.WaitForExit();
var commit = proc.StandardOutput.ReadToEnd();
var commitLine = commit.Split('\n')[2];
var commitValue = commitLine.Split(' ')[0];
#>
namespace MyCoolApplication
{
public partial class App : Application
{
public const string VersionSHA1 = @"<#= commitValue #>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment