Auto-Incrementing Build Numbers in Visual Studio.NET
Every Windows executable binary file (EXE, DLL, etc) has a version consisting of the following elements and format: Major.Minor.Build.Revision. To many software users, this is just a random string of numbers. For those that develop and deploy software though, this version information is important, even crucial in troubleshooting situations. Have you ever wondered how the version is controlled or set, and how you can manage the version in your own Visual Studio projects?
Visual Studio provides a default algorithm for building and assigning assembly version information when compiling an assembly. While the default algorithm does not automatically increment the major and minor elements of the version, it can increment the build and revision elements. The build element reflects the number of days since January 1, 2000 and the revision element reflects the number of seconds since midnight divided by two (2). To enable auto-versioning within Visual Studio, follow these simple steps for a C# project (VB projects follow identical steps with slightly different formatting).
- Open the file AssemblyInfo.cs
- Change [assembly: AssemblyVersion("1.0.0.0")] to [assembly: AssemblyVersion("1.0.*")]
- Remove [assembly: AssemblyFileVersion("1.0.0.0")]
- Rebuild the project and verify that the version is incremented properly by viewing the properties of the newly compiled assembly
Incrementing versions is a wise choice to provide traceability through multiple published versions of code. If you find that just tracking to the build and revision is not sufficient for your needs, it is also possible to leverage other aspects of Visual Studio in order to implement custom auto-incrementing algorithms. If you’re having trouble getting auto-versioning setup for your development projects, contact us to see if we can help. If you’re an expert at this sort of thing and have additional tips and tricks to share, please leave us a comment.
Tags: development, Microsoft, programming, Revision Control, version control, Visual Studio.NET
Read more posts by Paul Luc





January 26th, 2010 at 1:05 pm
You can also do this in the Visual Studio IDE. Click the “Assembly Information…” button on the Application tab of the Project Properties page and change the Assembly and File Version entries as shown above.
January 26th, 2010 at 7:31 pm
Thanks for the comment, Mike. While it’s true that you can edit assembly version information via the IDE, you must first remove the AssemblyFileVersion attribute from the AssemblyInfo.cs file in order for Visual Studio to apply auto-incrementing. Simply clearing the field values for the assembly file version via the IDE will result in a format-related exception.
May 17th, 2010 at 4:39 pm
Automatic version increments for specific builds (i.e. debug and release). You can tell it to increment the version only when doing a Release build.
http://autobuildversion.codeplex.com/
May 25th, 2010 at 8:58 am
Thanks for the feedback, Floyd. That’s a great example of a custom auto-incrementing algorithm.
September 1st, 2010 at 7:06 pm
Great article, it’s a little known feature that not many developers remember to leverage, especially on the Asp.Net side of coding. Personally I prefer a nightly TFS build and letting the build dictate those revision numbers.