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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s