Skip to content

Instantly share code, notes, and snippets.

@pardeike
Last active July 22, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pardeike/c36c4007b2855bc85950b59ade935bac to your computer and use it in GitHub Desktop.
Save pardeike/c36c4007b2855bc85950b59ade935bac to your computer and use it in GitHub Desktop.
AssemblyInfo.cs template with automatic version number calculation
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- add this to the end of the Project -->
<Target Name="TransformOnBuild" BeforeTargets="BeforeBuild">
<PropertyGroup>
<!-- CHANGE TO YOUR CORRECT PATH, THIS IS FOR VISUAL STUDIO 2017 COMMUNITY EDITION -->
<_TransformExe>$(MSBuildExtensionsPath)\..\Common7\IDE\TextTransform.exe</_TransformExe>
<_TextTransform>$(ProjectDir)Properties\AssemblyInfo.tt</_TextTransform>
<_TextTransformResult>$(ProjectDir)Properties\AssemblyInfo.cs</_TextTransformResult>
</PropertyGroup>
<Exec Command="del &quot;$(_TextTransformResult)&quot;" />
<Exec Command="&quot;$(_TransformExe)&quot; &quot;$(_TextTransform)&quot; -out &quot;$(_TextTransformResult)&quot;" />
</Target>
<!-- also include this AssemblyInfo.tt in the Properties folder
<#@ template language="C#" #>
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("TITLE")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Andreas Pardeike")]
[assembly: AssemblyProduct("PRODUCTNAME")]
[assembly: AssemblyCopyright("Copyright © xxxx")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("00000000-0000-0000-0000-000000000000")]
[assembly: AssemblyVersion("<#= this.BaseVersion #>.<#= this.RevisionNumber #>")]
[assembly: AssemblyFileVersion("<#= this.BaseVersion #>.<#= this.RevisionNumber #>")]
<#+
// you can go all in here, but we just change the 1.0.0.xxxx part as an example
string BaseVersion = "1.0.0";
int RevisionNumber = (int)(DateTime.UtcNow - new DateTime(2017,7,19)).TotalSeconds % 10000;
#>
-->
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment