Skip to content

Latest commit

 

History

History
94 lines (74 loc) · 2.73 KB

VersionAutoIncrement.md

File metadata and controls

94 lines (74 loc) · 2.73 KB

Application Version Auto Increment

You can automatize the assembly version increment, after every build with these 2 steps :

1 ) Add AssemblyVersion.tt in base folder of your EXE project.

AssemblyVersion in project folder

Delete other [assembly:AssemblyVersion(...)] attribute present in project

AssemblyVersion Attribute

2) Copy this code precompilation event

"$(DevEnvDir)tf.exe" checkout "$(ProjectDir)AssemblyVersion.cs"
set textTemplatingPath="%CommonProgramFiles(x86)%\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe"
if %textTemplatingPath%=="\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe" set textTemplatingPath="%CommonProgramFiles%\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe"
%textTemplatingPath% "$(ProjectDir)AssemblyVersion.tt"

Reference Documentation

AssemblyVersion.tt

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
<#
     int major = 0;
     int minor = 0;
     int build = 0;
     int revision = 0;

     try
     {
         using(var f = File.OpenText(Host.ResolvePath("AssemblyVersion.cs")))
         {
             string maj = f.ReadLine().Replace("//","");
             string min = f.ReadLine().Replace("//","");
             string b = f.ReadLine().Replace("//","");
             string r = f.ReadLine().Replace("//","");

             major = int.Parse(maj);
             minor = int.Parse(min);
             build = int.Parse(b);
             revision = int.Parse(r) + 1;
         }
     }
     catch
     {
         major = 1;
         minor = 0;
         build = 0;
         revision = 0;
     }
 #>
 //<#= major #>
 //<#= minor #>
 //<#= build #>
 //<#= revision #>
 //
 // 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("1.0.<#= revision #>.0")]

AssemblyVersion.cs

//1
//0
//0
//1
//
// 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("1.0.1.0")]