[SOLVED] Create dynamic Assembly Version including date and random revision number


I’m looking for a way of creating a dynamic Assembly Version for my ASP.NET MVC5 solution so that it would follow the format:


For example:


Ideally I would like to do the following in AssemblyInfo.cs:

DateTime dt = DateTime.Today;
[assembly: AssemblyVersion(String.Format("{0}.{1}.{2}.*", dt.Year, dt.Month. dt.Day))]

I’m aware this isn’t possible though.

Is there an alternative way of achieving this?


Versions are usually set by the build server however you can use a T4 template to generate your assembly info. I do this so I don’t have to change dates manually. Add a file called AssemblyInfo.tt and add the following to it:

<#@ template language="C#" #>
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;

[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyConfiguration("Release")]

[assembly: AssemblyCompany("My Company")]
[assembly: AssemblyProduct("My Product")]
[assembly: AssemblyCopyright("Copyright © My Company <#=DateTime.Now.Year#>")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("")]
// etc.

Add the code you need to generate your version number. For more information see: http://msdn.microsoft.com/en-us/library/bb126445.aspx

Answered By – Ananke

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *