Web Projects Can Have Version Numbers Too!

When you create a web project with Visual Studio, you might notice that it does not create an AssemblyInfo file for you. I’m not really sure why, but what if you want to give your site a version number like any other .NET project? Well you can… just have to create one manually. Simple create a new file called AssemblyInfo.cs or .vb and copy the following into it (c#):

using System.Reflection;
[assembly : AssemblyTitle ("Acme Admin Site" )]
[assembly : AssemblyDescription ("Acme Administration Web Site" )]
[assembly : AssemblyCompany ("Acme, Inc" )]
[assembly : AssemblyProduct ("Acme Administration Web Site" )]
[assembly : AssemblyCopyright ("Copyright \uc1\u169? 2011 Acme, Inc." )]
[assembly : AssemblyVersion ("2010.1.0.1" )]
[assembly : AssemblyFileVersion ("2010.1.0.1" )]

This info can be used in help pages etc. I use it in a WCF project to return the version number so customers or QA always know what version the site is, which is very useful when logging issues or enhancement requests. Here is how you can retrieve the version number  in c#:

var version = typeof (MyService).Assembly.GetName().Version.ToString();

Tip By: David McCarter