Auto Version Number in C#

Here’s a useful little tip:

In your AssemblyInfo.cs file, modify your assembly version number to auto increment. First, replace the last zero with an asterisk.


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

Then later, you can reference the version number with:


System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

You can then reference your version number as part of your other debug info.

The rules for how the increment occurs can be found here: AssemblyVersionAttribute

Thanks to Champlain College student Andrew Auclair for finding this reference in Stack Overflow.

A more robust and flexible solution can be found here. However, in many cases, all you need is the ability to ensure that two running projects are the same version, in which case the first solution is sufficient.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.