Welcome to MSDN Blogs Sign in | Join | Help

How To: Update Assembly Version Numbers with MSBuild

UPDATE: For information on the "Y7K" or "2007" issue, see our new blog entry

One of our most frequently asked questions is: "How do update my assembly version numbers at build time?". Unfortunately our answer has been "you can't". Until today, that is.

I just posted a new task, AssemblyInfoTask, at GotDotNet. It provides complete support for a wide variety of version number styles, from a fixed number to numbers that change daily to numbers that increment on every build. It also supports setting other properties such as AssemblyTitle, AssemblyCopyright, etc.

Even better, we've posted the complete source code, unit tests (that run in Visual Studio Team System), and raw documentation for the task under the new Microsoft Community License. Try not to laugh too hard when you look at the code. Remember, I don't write code for a living, I'm one of those touchy-feely Program Manager people :)

If all you want to do is get Visual Studio-style build numbers, of the form 1.0.yyMMdd.revision (for example, 1.0.51111.02 for the third build today), then you simply add the following line to your project file after any existing <Imports>:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets"/>

If anyone has trouble getting it to work, has comments, questions, or suggestions, please send 'em our way to msbuild@microsoft.com or post to our forum.Enjoy!

[ Author: Neil Enns ]

Published Friday, November 11, 2005 10:38 PM by msbuild

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Friday, November 11, 2005 6:29 PM by Phil Wright

# re: How To: Update Assembly Version Numbers with MSBuild

This is just what I needed. I was just about to write a custom task myself to set the version number and thought I would do a search just in case this common requirement was already done. Thanks!

P.S. I'll let you know if I find any bugs!

Phil Wright
Free VS2005 GUI Controls...
http://www.componentfactory.com
Friday, November 11, 2005 10:47 PM by Jason Kemp

# re: How To: Update Assembly Version Numbers with MSBuild

Great! I was looking for something like this.

I quickly glanced at the code and I have a quick question about something I noticed: why did you create your own Version class when there is System.Version built into the BCL? Is it 'cause yours does something it doesn't?
Sunday, November 13, 2005 12:17 AM by msbuild

# re: How To: Update Assembly Version Numbers with MSBuild

Good question, Jason. I must admit when I started with the task I didn't actually realize System.Version existed. At one point during the development I did try and switch to using the .NET Framework class.

The difference is in the property types. The .NET Version class stores everything as ints, and my class uses strings. This is to support leading numbers when doing custom formatting. For example, it's customary in Visual Studio-land for our revisions to be "01", "02", etc., rather than being "1", "2" and so on. If this gets stored as an int the custom formatting is lost. You can see this at work in the UpdateVersionProperty() method.

In hindsight I might be able to everything as ints in the Framework class and then do the formatting when I actually spit out the version number to the file. Perhaps in v1.1 :)

Neil
Sunday, November 13, 2005 12:18 AM by msbuild

# re: How To: Update Assembly Version Numbers with MSBuild

Phil,

You also have to let me know if it works :)

Neil
Friday, November 18, 2005 4:54 AM by Steinar Herland

# re: How To: Update Assembly Version Numbers with MSBuild

Nice work. I'm considering changing the version numbering we use in our products, and really like the Visual Studio-style build numbers. (1.0.yyMMdd.revision) However, when I looked into the System.Version class it became obvious that this style will only work for about a year(!)

The problem is that System.Build, .Major, .Minor and .Revision are System.Int32 :(

January 1. 2007 => "1.0.70101.0"
70101 > 65534 => The specified version '1.0.70101.0' is invalid.

(Interestingly the error only occurs if set using the AssemblyVersion attribute. When removing the AssemblyVersion, and only using AssemblyFileVersion, VS is not giving compilation errors, but AssemblyFileVersion("1.0.70101.0")] gives the assembly File Version 1.0.4565.0.0 and Product Version 1.0. 70101.0)

Do you know which build-number-style that will be used on the next version of VS? - Assuming it won't be released next year. :)

Steinar
Tuesday, November 29, 2005 11:18 AM by Bob Builder

# re: How To: Update Assembly Version Numbers with MSBuild

If I have a .sln (converted to a msbuild-proj-xml file), how can I in one place set the version of every assembly?
Thursday, December 01, 2005 1:14 AM by msbuild

# re: How To: Update Assembly Version Numbers with MSBuild

Steinar, I'm not sure what we're planning to do about that problem. I guess it's a year 2010 bug :)

Neil
Thursday, December 01, 2005 1:16 AM by msbuild

# re: How To: Update Assembly Version Numbers with MSBuild

Bob,

Excellent question. You should be able to insert the necessary target call into your msbuild project XML file at the start of the build process. I don't have a converted file handy at the moment to mess with this (no VS2005 at home!). Can you shoot me mail at msbuild@microsoft.com to ask your question so I don't forget? That way I can look at it on Friday (tomorrow's swamped) and I'll get back to you in email as well as on the blog.

Neil
Wednesday, December 07, 2005 2:14 PM by Manish Agrawal

# re: How To: Update Assembly Version Numbers with MSBuild

<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets"/>

This is working perfectly fine with the Projects having AssemblyInfo.cs file.

But how can I update the Version Numbers of the Assemblies generated by the <AspNetCompiler> task for a Website.
All the assemblies generated here show Version as 0.0.0.0

How can I generate the AssemblyInfo.cs file for the Website in advance.

I am using Visual Web Developer and do not have VS 2005.

Please suggest..

Thanks in advance
--Manish
Thursday, December 22, 2005 11:15 AM by Steinar Herland

# re: How To: Update Assembly Version Numbers with MSBuild

It's not a 2010, its a 2007 bug :)
Wednesday, January 11, 2006 3:25 PM by Valkyrie-MT

# re: How To: Update Assembly Version Numbers with MSBuild

Wait a minute... I don't think there is a Year 2007 problem. Int32 has a max value of 2,147,483,647. I think you are confusing this with UInt16. So turn that frown upside down! :) Because it should work for a million years! We may indeed have a Million year problem though...

-Valkyrie-MT

Steinar said:

The problem is that System.Build, .Major, .Minor and .Revision are System.Int32 :(

January 1. 2007 => "1.0.70101.0"
70101 > 65534 => The specified version '1.0.70101.0' is invalid.

Monday, January 30, 2006 9:59 PM by Tobias

# re: How To: Update Assembly Version Numbers with MSBuild

The max build number is actually System.UInt16.MaxValue - 1 (65,534) and not Int32 (2,147,483,647). This is true for VS2005.

[assembly: AssemblyVersion("1.0.65534.0")]
Works

[assembly: AssemblyVersion("1.0.65535.0")]
Produces error: Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.0.65535.0' is invalid'

An alternative versioning is [major.minor.yymm.ddrrr] as long as you produce no more than 1000 builds on any given day.

Tobias.









Wednesday, February 01, 2006 3:15 PM by Tobias

# re: How To: Update Assembly Version Numbers with MSBuild

Actually the alt versioning system won't work because of leading zero issue.

Tobias.
Monday, February 13, 2006 8:37 AM by Leo

# re: How To: Update Assembly Version Numbers with MSBuild

Hi, How can I use this on a Web Project ?

Thanks
Monday, February 13, 2006 11:32 AM by Jon

# re: How To: Update Assembly Version Numbers with MSBuild

Hi

I was wondering if we had resolved the 2007 bug yet or not? (other than changing the formating of build version number)

Jon
Tuesday, March 07, 2006 12:07 PM by Sean Perkin

# re: How To: Update Assembly Version Numbers with MSBuild

How about changing the version number format to:

1.0.0.0

major.minor.patch.build_increment
Wednesday, April 12, 2006 3:56 AM by sacrosancttayyar@gmail.com

# re: How To: Update Assembly Version Numbers with MSBuild

hi everybody,
i am new at VS (studying c#) and i eonder that how can i open and COPiLE VS2005 projects withs VS 2003 (on a computer that have not NETFRAMEWORK 2.X  only have 1.1)
maybe some assembly works but i really woder this..
in my school computers dont have  netframework2.x only 1.1. and VS2003 so my projects (created by VS2005) cant be opened in my schools computers..????
:(
maybe you say :MSBuild Toolkit bla bla ..
thanks for now.

[sorry for my bad english-- you are not babysitter so you have not to answer this topic :) ]
Friday, May 19, 2006 1:17 AM by RajM

# re: How To: Update Assembly Version Numbers with MSBuild

How to implement versioning for native VC++ projects that are part of a sln.
Friday, June 02, 2006 8:39 AM by bobw

# re: How To: Update Assembly Version Numbers with MSBuild

I echo Leo's request: will this work on web projects?
Wednesday, September 06, 2006 1:58 AM by Jocke

# re: How To: Update Assembly Version Numbers with MSBuild

Does not work on mobile projects since ".NET Compact Framework" is differs from ".NET Framework" and System.Reflection namespace does not contain AssemblyFileVersion class.

Following error occurred:
=======================
Unable to update the AssemblyFileVersion for Properties\AssemblyInfo.cs: No stub entry for AssemblyFileVersion was found in the AssemblyInfo file.
=======================

Please help!
Thursday, September 07, 2006 9:59 AM by Ian

# re: How To: Update Assembly Version Numbers with MSBuild

I need to charge the custom buiild number so that it contains my local time (Copenhagen) , can i use this to do it

thanks
Friday, September 15, 2006 7:19 AM by matt law

# re: How To: Update Assembly Version Numbers with MSBuild

Won't work full stop with a project under Subversion control...

Unable to update the AssemblyFileVersion for _svn\text-base\AssemblyInfo.cs.svn-base: No stub entry for AssemblyFileVersion was found in the AssemblyInfo file.

Shame :(
Thursday, September 21, 2006 8:43 AM by Beefeater

# re: How To: Update Assembly Version Numbers with MSBuild

I can't seem to find the source code on the Microsoft Community License page.   Could you please post the link?

# Edgardo Rossetto .NET &raquo; Blog Archive &raquo; Como incrementar el n??mero de versi??n de los assemblies con MSBuild

Wednesday, October 25, 2006 3:00 AM by Corina

# re: How To: Update Assembly Version Numbers with MSBuild

Hello! I want to update version number in AssemblyInfo.cs but I don't want this format: 1.0.yyMMdd.revision. I tried using <Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets"/> put in the end of the .csproj file and then, as a test, I tried using command line to execute:

MSBuild.exe <testProject>\Test.csproj /t:Rebuild /p:Assembl

yRevisionType="NoIncrement" /p:AssemblyFileRevisionType="NoIncrement" /p:AssemblyVersion="0.1.38.*" /p:AssemblyFileVersion="0.1.38.*" but in the AssemblyInfo file I got [assembly: AssemblyVersion("1.0.061025.05")] which is not what I want. Can you help me, please?

Monday, November 20, 2006 4:43 AM by Woundering

# re: How To: Update Assembly Version Numbers with MSBuild

Why do I need this util? Why cant I specify the assembly version in assembly.vb? Currently my build environment is automated to do that, and I havn't found any drawbacks, yet.

Tuesday, December 05, 2006 10:27 PM by Sean McBreen's WebLog

# Visual Studio Team System Resources (VSTS)

I'm very proud of Visual Studio Team System and what Microsoft have done here - I've blogged about it

Monday, December 11, 2006 5:56 PM by Jon

# re: How To: Update Assembly Version Numbers with MSBuild

I installed the downloaded file and created an C# project to test it. I found the following properties seems not work for me:

   <AssemblyMajorVersion>2</AssemblyMajorVersion>

   <AssemblyMinorVersion>0</AssemblyMinorVersion>

   <AssemblyFileMajorVersion>2</AssemblyFileMajorVersion>

   <AssemblyFileMinorVersion>0</AssemblyFileMinorVersion>

I added these properties to the project file, after built it each time the Revision number getting increased and the major and minor numbers were keeping not changed, always "1.0".

I am using VS 2005 + TFS.

Can you point out what's wrong with my steps?

Thanks,

Jon

Monday, December 11, 2006 6:18 PM by Jon

# re: How To: Update Assembly Version Numbers with MSBuild

Ok, once I updated these properties in Microsoft.VersionNumber.targets, it works perfect.

Thanks.

Sunday, December 24, 2006 6:00 AM by Michael S. Combs

# re: How To: Update Assembly Version Numbers with MSBuild

Hi, I'm trying to get this to work along side with my SVN plugin for vs2005, but it seems that this wants to change the values of an AssemblyInfo.cs.svn-base file.

This file is located inside a hidden directory called .svn

Maybe an update for this could ignore files inside hidden folders.

Monday, January 01, 2007 5:15 PM by Joey

# re: How To: Update Assembly Version Numbers with MSBuild

Just wondered if any one had come up with a workaround to the 2007 build number issue. I have just tried to build a project 1 Jan 2007 and it threw the error mentioned in the comments above.

Monday, January 01, 2007 8:10 PM by Steve

# re: How To: Update Assembly Version Numbers with MSBuild

Same 2007 problem here... all of our nightly builds have failed.  I hope we haven't followed Microsoft into a brick wall with their versioning standard.

Tuesday, January 02, 2007 4:24 AM by Chris

# re: How To: Update Assembly Version Numbers with MSBuild

I have also come into the office this morning to find that the last two overnight builds have failed with the "2007 problem".

Has anyone made any progress with this problem?

Tuesday, January 02, 2007 8:05 AM by Gavin

# re: How To: Update Assembly Version Numbers with MSBuild

Same '2007' problem with us as well.... Oops! We've changed our scripts to add the 4 'DateString' and 'MMdd' lines below. i.e. remove the YY part. It'll get us through the next few days.

 <PropertyGroup>

   <!-- Assembly version properties. Add others here -->

   <AssemblyMajorVersion>2</AssemblyMajorVersion>

   <AssemblyMinorVersion>1</AssemblyMinorVersion>

   <AssemblyFileMajorVersion>2</AssemblyFileMajorVersion>

   <AssemblyFileMinorVersion>1</AssemblyFileMinorVersion>

 <AssemblyBuildNumberType>DateString</AssemblyBuildNumberType>

   <AssemblyBuildNumberFormat>MMdd</AssemblyBuildNumberFormat>

   <AssemblyFileBuildNumberType>DateString</AssemblyFileBuildNumberType>

   <AssemblyFileBuildNumberFormat>MMdd</AssemblyFileBuildNumberFormat>

   <!-- TF.exe -->

   <TF>&quot;$(TeamBuildRefPath)\..\tf.exe&quot;</TF>

   <!-- AssemblyInfo file spec -->

   <AssemblyInfoSpec>AssemblyInfo.cs</AssemblyInfoSpec>

 </PropertyGroup>

Tuesday, January 02, 2007 9:09 AM by TLoomos

# re: How To: Update Assembly Version Numbers with MSBuild

I implemented a new versioning scheme as described in http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1058284&SiteID=1.  It keeps with the spirit of the version numbering scheme but it's far less convenient than yymmdd.  This implementation sets the build number to the 2 digit year followed by the 3 digit day of the year. This scheme will work until 2065 :)

To implement this, follow these steps:

1) Get the AssemblyInfoTask source from http://www.gotdotnet.com/codegallery/releases/viewuploads.aspx?id=93d23e13-c653-4815-9e79-16107919f93e

2) Open AssemblyInfoTask.cs and make the following changes:

   Go to the end of the file and add another entry to the IncrementMethod enum - I used DayOfYear = 3

   Search for "Switch" in the file and add another case for the new increment method.  Copy the DateString case but change the newVersionNumber to be:

string newVersionNumber = DateTime.Now.Year.ToString().Substring(2) + String.Format("{0:000}",DateTime.Now.DayOfYear);

3) Compile the app (remember it needs to be strong named if you want it in the GAC)

4) Install the assembly into the GAC

5) Open <program files>\MSBuild\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets in Notepad - look for the task import (usingTask) and change the PublicKeyToken to match the one from your new assembly.

Tuesday, January 02, 2007 12:41 PM by ckw

# re: How To: Update Assembly Version Numbers with MSBuild

This seems like the best solution (much better than resetting the year to 1 which is an option I have seen suggested elsewhere).

Are the (strongly named) binaries going to be reposted on GotDotNet?

Tuesday, January 02, 2007 12:42 PM by ckw

# re: How To: Update Assembly Version Numbers with MSBuild

This seems like the best solution (much better than resetting the year to 1 which is an option I have seen suggested elsewhere).

Are the (strongly named) binaries going to be reposted on GotDotNet?

Wednesday, January 03, 2007 9:32 AM by frosted

# re: How To: Update Assembly Version Numbers with MSBuild

hehe, quite funny :)

I'll be waiting for a new official update, I can work around with this 2007 problem for now.

Wednesday, January 03, 2007 4:09 PM by msbuild

# re: How To: Update Assembly Version Numbers with MSBuild

Hey guys,

Looks like people have already figured this out, but I've blogged two entries about the issue. You can read details at http://blogs.msdn.com/msbuild/archive/2007/01/03/fixing-invalid-version-number-problems-with-the-assemblyinfotask.aspx and http://blogs.msdn.com/msbuild/archive/2007/01/03/why-are-build-numbers-limited-to-65535.aspx.

Neil

Monday, February 26, 2007 2:50 AM by sur

# re: How To: Update Assembly Version Numbers with MSBuild

can someone give me suggestions.

i'm facing the following problem

aseemblyinfo.cs file of main project is getting updated but not for the depended projects .these depended projects are defined in the .sln file of main project.

sud i call this target "update assemblyinfo "for all depended projects separately or is there any other method??

Tuesday, March 27, 2007 10:14 AM by Danny

# re: How To: Update Assembly Version Numbers with MSBuild

It seems that

   <AssemblyMajorVersion>1</AssemblyMajorVersion>

   <AssemblyMinorVersion>0</AssemblyMinorVersion>

only work in the targets file, not in the project file. But this file is shared for all projects. How can I set these so they are specific to each project?

Thanks

Danny

Friday, May 11, 2007 5:23 PM by Re-inventing The Wheel

# It's no good down here, I can't maneuver!

I'm going to stop writing new tasks for a couple of entries while I take some time to clean things up.

Sunday, May 20, 2007 9:06 PM by lextm

# re: How To: Update Assembly Version Numbers with MSBuild

Danny,

You can copy the targets file to a local folder and import the local version instead of the one located in MSBuildExtensions. Then each solution or project use a corresponding local copy.

==============

It seems that

  <AssemblyMajorVersion>1</AssemblyMajorVersion>

  <AssemblyMinorVersion>0</AssemblyMinorVersion>

only work in the targets file, not in the project file. But this file is shared for all projects. How can I set these so they are specific to each project?

Thanks

Danny

Thursday, June 07, 2007 7:02 AM by Dalo

# re: How To: Update Assembly Version Numbers with MSBuild

Hi,

I'm using AssemblyInfoTask to update the Assembly info with MSBuild

<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets"/>

My problem is that when it updates

<Assembly: AssemblyCompany("The Company á")>

it removes the character á.  Any ideas on how I get AssemblyInfoTask to recognise accents etc...?

Thanks

Sunday, August 12, 2007 11:22 PM by Michael

# re: How To: Update Assembly Version Numbers with MSBuild

Seems that godotnet does not exist anymore, but i cannot find the Task on CodePlex either. Where to get it?

Monday, August 13, 2007 12:56 AM by deerchao

# re: How To: Update Assembly Version Numbers with MSBuild

For those who can't find where to download it now like me, it's now aviable at http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=5C455590-332C-433B-A648-E368B9515580

Thursday, November 15, 2007 12:42 PM by mjdgddy

# re: How To: Update Assembly Version Numbers with MSBuild

I'm really surprised no one has suggested using a year indicator with a Julian day of year instead of the month/day.  This would save one digit and get us past this issue.

Wednesday, November 21, 2007 4:51 PM by Amit Pabari

# re: How To: Update Assembly Version Numbers with MSBuild

Actully i need the same solution for .NET 2003 and i dont know how can i do that..???

Can any one help me.......??????

Friday, November 30, 2007 12:18 PM by MSBuild Team Blog

# Response to the feature poll

There were over 80 responses to my recent post asking for feedback on where MSBuild should be heading

Saturday, December 08, 2007 10:14 PM by enough_already...

# re: How To: Update Assembly Version Numbers with MSBuild

Isn't it time ~somebody~ came up with a decent way to control version numbers associated with the build process????????

I have run into several different companies all ~home-brewing~ their own version incrementing scheme... let's get it together people... how long have version numbers been around now???

Tuesday, February 19, 2008 10:02 AM by Roberto

# re: How To: Update Assembly Version Numbers with MSBuild

When searching the URL http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=5C455590-332C-433B-A648-E368B9515580 , i received the message

"The GotDotNet site has been shut down". I tried to search the new site, but was unable due to security restrictions at my enterprise. Please, could anyone post the new site for the URL above? Thanks.

Tuesday, March 18, 2008 7:13 PM by ychen

# re: How To: Update Assembly Version Numbers with MSBuild

Hi,

   I'm facing a problem as described in http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2989436&SiteID=1

   Could anyone help me solve that problem? Thanks.

Wednesday, March 19, 2008 1:07 AM by jiro

# re: How To: Update Assembly Version Numbers with MSBuild

Ok. while YYDDD is convinient. i really dont want to download the source file and modify them. personal reasons and just want to see a clear yymmdd in there.

instead i used

major.minorYY.MMDD.Revisions

since i manually input the minor revisions.

might as well edit it yearly

so i formated it in my project as

minorYY

sample

1.108.0319.05

major -1

minor -1 (with year 08)

build - mmdd

revision - auto increment

Thursday, May 22, 2008 10:18 AM by Richard J Foster

# re: How To: Update Assembly Version Numbers with MSBuild

I'm also looking for the new URL (assuming this potentially useful task didn't go the same way as the GotDotNet site). Can anyone help?

Friday, July 11, 2008 5:32 AM by Yacine

# re: How To: Update Assembly Version Numbers with MSBuild

This seems to be the new URL:

http://www.codeplex.com/tfsbuildversionsync

Wednesday, July 23, 2008 1:49 AM by Jandost

# re: How To: Update Assembly Version Numbers with MSBuild

Hi,

AssemblyInfoTask is not longer in the link you provided on GotDotNet. I found it anyways by searching internet from other sources. It will be great if you can update the link for other people to find it easier.

Regards,

Wednesday, July 23, 2008 2:08 AM by Jandost

# re: How To: Update Assembly Version Numbers with MSBuild

Hi,

I am facing a problem using AssemblyTaskInfo in my Subversion source Control. After adding IMPORTS line to my project file, I am continuously getting UNAUTHORIZED ACCESS (ACCESS DENIED to \SVN\txt-bases\Assembly***.cs file)

Have you seen this error before? Any workaround?

Wednesday, July 30, 2008 2:20 PM by FreeToDev

# re: How To: Update Assembly Version Numbers with MSBuild

A lightweight alternative to versioning: http://freetodev.spaces.live.com/blog/cns!EC3C8F2028D842D5!547.entry

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker