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:
YYYY.M.D.XXXXX
For example:
2014.7.25.45261
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;
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif
[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("1.0.0.0")]
// etc.
Add the code you need to generate your version number. For more information see: http://msdn.microsoft.com/en-us/library/bb126445.aspx