Skip to content

Instantly share code, notes, and snippets.

@ShawInnes
Created February 22, 2014 13:43
Show Gist options
  • Save ShawInnes/9154988 to your computer and use it in GitHub Desktop.
Save ShawInnes/9154988 to your computer and use it in GitHub Desktop.
Automatic AssemblyVersion File - T4 Template
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="System.IO" #>
<#
var hostServiceProvider = (IServiceProvider)Host;
var dte =
(EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE));
var activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
var dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0);
var defaultNamespace =
dteProject.Properties.Item("DefaultNamespace").Value;
var templateDir = Path.GetDirectoryName(Host.TemplateFile);
var fullPath = dteProject.Properties.Item("FullPath").Value.ToString();
fullPath =
fullPath.EndsWith("\\")
? fullPath.Substring(0, fullPath.Length-1)
: fullPath;
var subNamespace =
templateDir.Replace(fullPath, string.Empty).Replace("\\", ".");
var fileNamespace = string.Concat(defaultNamespace, subNamespace);
#>
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//
using System.Reflection;
[assembly: AssemblyVersion("0.1.0.<#= this.RevisionNumber #>")]
[assembly: AssemblyFileVersion("0.1.0.<#= this.RevisionNumber #>")]
namespace <#= fileNamespace #>
{
public static class VersionInfo
{
private static string _version = null;
public static string Version {
get
{
if (_version == null)
_version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
return _version;
}
}
}
}
<#+
int RevisionNumber = (int)(DateTime.UtcNow - new DateTime(2010, 1, 1)).TotalDays;
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment