Click here to Skip to main content
14,207,985 members
Click here to Skip to main content
Add your own
alternative version


61 bookmarked
Posted 11 Sep 2003

Build Number Automation for Visual Studio .NET Projects

, 18 Sep 2003
Rate this:
Please Sign up or sign in to vote.
A Visual Studio .NET macro to automatically update the build number written in AssemblyInfo.cs.


Hi. It's the first time that I am writing a CodeProject article. I feel honored. :) Anyway, Sometimes I'm too lazy to manually update the build number of my software every time a new build comes out. And I thought to find a similar tool and customize it to work as I wanted would be more complicated than writing my own. So here's the macro, to automatically update the build number in AssemblyInfo.cs for you. (For VB.NET projects this would be AssemblyInfo.vb) I kept it simple, so you can get the idea and do customizations yourself.

How does it work

Basically the macro, once triggered, tries to open the file AssemblyInfo.cs from a path you specify, and locates the version string (something like this in C#: [assembly:AssemblyVersion("1.0.0220.1536")]) using regular expression. It then updates the old revision and build numbers based on some rules, and writes the file back. At the very end, an optional Build.BuildSolution command is called. If you want to update the build number every time a new build process is kicked off, run this macro instead of using the normal Build->Build Solution menu item.

The rules of the calculation of build numbers are fairly simple. Normally a version number will look like this: AA.BB.CCDD.EEFF, where AA is the major version and BB is the minor version. These two are untouched: you have to set them yourself. The CCDD.EEFF part is modified automatically. CC will be used to represent the number of months elapsed since the starting of the project, and DD the number of days after those months. EE and FF will be the hours and minutes the build was created in that day. Therefore for example, if the project started on Jan 10, 2003 with version 1.0 and you run this macro on Mar 15, 2003 at 14:00, this is the build number that comes out of the calculation: 1.0.0205.1400. (I was told that this is the Microsoft's way of numbering the build.)

How to make it work

You will have to create a new macro with the source code included in this article. I assume you already know how to do that. Then, you will have to edit the source code to make it work for your project. The followings are what you need to change:

  1. Change variable theProjectStartingDate. This represents the starting date of your project, on which the calculation is based.
  2. Change variable theAssemblyInfoFilePath. The path is relative to the path of the project file (*.csproj for C#) I put all my source files under Source\ directory, so it's Source\AssemblyInfo.cs in the sample code. VB.NET users have to change the file name to AssemblyInfo.vb, and also the regular expression that parses the VB version string, correctly. I'm sorry but I'm not a VB programmer.
  3. Change variable theBuildSolution to False if you don't want to build after the macro is done.
  4. Change the default version string from 1.0.* to something like so the macro can find it for the first time.

If you run this macro with AssemblyInfo.cs file open, you will be prompted whether to reload it. But the build process will not be interrupted.


This is it. It doesn't do much, and it may have problems handling multiple projects in one solution. But I think the code is comprehensive enough for other people to customize. Again, I'm not a VB programmer, so please don't laugh if you find this article childish. Thanx :)


  • Sep 13 2003 - Initial release
  • Sep 19 2003 - Source updated



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Darrel Liu
Web Developer
United States United States
Darrel is a perfectionist at heart: he refuses to work on code that does not adopt perfect indentation. He usually has to spend a great deal of time doing reformatting. This has made him have little achievement as a coder since the beginning of his programmer's life at age 12.

Other than programming, he drives his 2003 Desert Silver Acura RSX, watches movies and listens to soft music.

Comments and Discussions

GeneralMy vote of 5 Pin
Bob Murphy15-Dec-10 10:12
memberBob Murphy15-Dec-10 10:12 
GeneralUsing with Express editions Pin
ashesman1-Jan-09 23:47
memberashesman1-Jan-09 23:47 
GeneralAlternative way Pin
Lex Li11-Jul-07 20:02
professionalLex Li11-Jul-07 20:02 
QuestionWhat is DTE Pin
T. Sampath27-Apr-07 4:52
memberT. Sampath27-Apr-07 4:52 
AnswerRe: What is DTE Pin
1.sladr25-Jun-07 22:50
member1.sladr25-Jun-07 22:50 
Generalit's not necessary to read the assemblyinfo file [modified] Pin
1.sladr23-Apr-07 1:12
member1.sladr23-Apr-07 1:12 
GeneralGreat.. Thanks. Pin
Michael Sync12-Jan-07 16:36
memberMichael Sync12-Jan-07 16:36 
GeneralGreat! Pin
BendanyQian14-Feb-06 18:50
memberBendanyQian14-Feb-06 18:50 
GeneralVersion Number Idea - Wrong Pin
AAMP10-May-05 1:58
memberAAMP10-May-05 1:58 
GeneralRemember to add a reference to VSLangProj.dll Pin
Yuh-Rong Leu14-Mar-05 21:28
sussYuh-Rong Leu14-Mar-05 21:28 
GeneralGetting the AssemblyVersion value Pin
raulhmacias3-Mar-04 13:51
memberraulhmacias3-Mar-04 13:51 
GeneralRe: Getting the AssemblyVersion value Pin
HairiDog23-Apr-04 7:03
memberHairiDog23-Apr-04 7:03 
You can use this code, be sure to change the app name "DatabaseFun.exe" to your exe/dll name.

System.Reflection.Assembly ASS = System.Reflection.Assembly.LoadFrom("DatabaseFun.exe");
MessageBox.Show("Version : " + ASS.GetName().Version.ToString());
catch(System.Exception exception)

GeneralRe: Getting the AssemblyVersion value Pin
Member 372056018-Jun-04 8:47
memberMember 372056018-Jun-04 8:47 
General© in the assembly-file Pin
thilol23-Jan-04 4:26
memberthilol23-Jan-04 4:26 
Generalproblem if AssemblyInfo.cs already open Pin
thilol30-Sep-03 2:27
memberthilol30-Sep-03 2:27 
GeneralUpdated for multiple C# project enumeration Pin
bcraun25-Sep-03 11:24
memberbcraun25-Sep-03 11:24 
GeneralRe: Updated for multiple C# project enumeration Pin
Darrel Liu25-Sep-03 12:05
memberDarrel Liu25-Sep-03 12:05 
GeneralFailed with VB.NET Pin
olinat24-Sep-03 12:54
memberolinat24-Sep-03 12:54 
GeneralRe: Failed with VB.NET Pin
Darrel Liu24-Sep-03 13:29
memberDarrel Liu24-Sep-03 13:29 
GeneralRe: Failed with VB.NET Pin
olinat24-Sep-03 13:36
memberolinat24-Sep-03 13:36 
QuestionAnybody can give me a walk-through? Pin
Hardy Wang17-Sep-03 5:37
memberHardy Wang17-Sep-03 5:37 
AnswerRe: Anybody can give me a walk-through? Pin
Darrel Liu17-Sep-03 7:00
memberDarrel Liu17-Sep-03 7:00 
GeneralRe: Anybody can give me a walk-through? Pin
Hardy Wang17-Sep-03 7:16
memberHardy Wang17-Sep-03 7:16 
GeneralRe: Anybody can give me a walk-through? Pin
Darrel Liu17-Sep-03 7:40
memberDarrel Liu17-Sep-03 7:40 
GeneralRe: Anybody can give me a walk-through? Pin
bebangs18-Mar-08 17:07
memberbebangs18-Mar-08 17:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190612.1 | Last Updated 19 Sep 2003
Article Copyright 2003 by Darrel Liu
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid