Automate Assembly Build Version

It is the most common requirement to many of us to show the proper assembly version and build version to our application. Now for every version you can either choose your assembly version yourself, or rather you try to find some alternative that Visual studio automatically increments the value of your Build version and/or assembly Version. In this post I will cover how you can apply this technique to your application, and will show you how to find the AssemblyVersion of your current assembly.

AssemblyVersionAttribute is a special class that allows you to deal with Build versions. Generally we specify the AssemblyVersion in AssemblyInfo.cs file that resides inside Project folder of any application. Lets check how it looks like :

But this means the assembly that it produces will be of version The numbers represents a Version object which represents respectively :
Major Version
Minor Version
Build Number and

To get the assembly Version from code, you can use the following :

AssemblyName aname = new AssemblyName(Assembly.GetAssembly(typeof(MyClass)).FullName);
Version v = aname.Version;
Console.WriteLine("Major : {0}, Minor : {1}, Build : {2}, Revision : {3}", v.Major, v.Minor, v.Build, v.Revision);

The code will show you the assembly version information where the type MyClass resides. You can also use Assembly.GetExecutingAssembly to get the Assembly related information on your currently executing assembly or any Reflection API to get information about any Assembly or Type.

Now To automate this version number we use WildCards. * is a wildcard that would be replaced by visual studio with the internal Build number, revision it generates. So if I specify

[assembly: AssemblyVersion("1.0.*")]

It will generate something for instance 1.0.2039.98489. You can also specify * after Build version. Say if I specify 1.0.0.*, it can generate Hence it depends on where you specify the wildcard character.

Remember the wildcard character can only be applied for AssemblyVersion. You cannot specify it for AssemblyFileVersion.

Thanks for reading this post.

I hope that come to you helpful.

Abhishek Sur

Abhishek Sur is a Microsoft MVP since year 2011. He is an architect in the .NET platform. He has profound theoretical insight and years of hands on experience in different .NET products and languages. He leads the Microsoft User Group in Kolkata named KolkataGeeks, and regularly organizes events and seminars in various places for spreading .NET awareness. He is associated with the Microsoft Insider list on WPF and C#, and is in constant touch with product group teams. He blogs at His Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook. Follow Abhishek at Twitter : @abhi2434