views:

3289

answers:

7

I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.* but it doesn't get me exactly what I want.

I'm also using a settings file and in earlier attempts when the assembly version changed my settings got reset to the default since the application looked for the settings file in another directory.

I would like to be able to display a version number in the form of 1.1.38 so when a user finds a problem I can log the version they are using as well as tell them to upgrade if they have an old release.

A short explanation of how the versioning works would also be appreciated. When does the build and revision number get incremented?

+21  A: 

With the "Built in" stuff, you can't, as using 1.0.* or 1.0.0.* will replace the revision and build numbers with a coded date/timestamp, which is usually also a good way. For more info, see the Assembly Linker Documentation in the /v tag.

As for automatically incrementing numbers, use the AssemblyInfo Task:

http://code.msdn.microsoft.com/AssemblyInfoTaskvers

This can be configured to automatically increment the build number.

There are 2 Gotchas:

  1. Each of the 4 numbers in the Version string is limited to 65535. This is a Windows Limitation and unlikely to get fixed.
  2. Using with with Subversion requires a small change:

Retreiving the Version number is then quite easy:

Version v = Assembly.GetExecutingAssembly().GetName().Version;
string About = string.Format(CultureInfo.InvariantCulture, @"YourApp Version {0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision);
Michael Stum
i just found this visual studio add-in that does something similar: http://autobuildversion.codeplex.com/
Jugglingnutcase
A: 

And, to clarify: In .net or at least in C#, the build is actually the THIRD number, not the fourth one as some people (for example Delphi Developers who are used to Major.Minor.Release.Build) might expect.

In .net, it's Major.Minor.Build.Revision.

Michael Stum
+2  A: 

What source control system are you using?

Almost all of them have some form of $ Id $ tag that gets expanded when the file is checked in.

I usually use some form of hackery to display this as the version number.

The other alternative is use to use the date as the build number: 080803-1448

engtech
Can you expand on "Almost all of them have some form of $ Id $ tag that gets expanded when the file is checked in". Specifically, do you know for subversiion?
Greg B
A: 

Some time ago I wrote a quick and dirty exe that would update the version #'s in an assemblyinfo.{cs/vb} - I also have used rxfind.exe (a simple and powerful regex-based search replace tool) to do the update from a command line as part of the build process. A couple of other helpfule hints:

  1. separate the assemblyinfo into product parts (company name, version, etc.) and assembly specific parts (assembly name etc.). See here
  2. Also - i use subversion, so I found it helpful to set the build number to subversion revision number thereby making it really easy to always get back to the codebase that generated the assembly (e.g. 1.4.100.1502 was built from revision 1502).
caryden
+1  A: 

FWIW, I use subversion, cruisecontrol and ant for my Delphi builds. I manually set the Major and Minor numbers. The third number is the subversion revision and the fourth is the cruisecontrol build number.

+2  A: 

VS.NET defaults the Assembly version to 1.0.* and uses the following logic when auto-incrementing: it sets the build part to the number of days since January 1st, 2000, and sets the revision part to the number of seconds since midnight, local time, divided by two.

Assembly version is located in a assemblyinfo.vb or assemblyinfo.cs file. From the file:

' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version 
'      Build Number
'      Revision
'
' You can specify all the values or you can default the Build and Revision Numbers 
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")> 

<Assembly: AssemblyVersion("1.0.0.0")> 
<Assembly: AssemblyFileVersion("1.0.0.0")>
Solracnapod
where do you have this info from? "sets the build part to the number of days since January 1st, 2000, and sets the revision part to the number of seconds since midnight, local time, divided by two."days since 1st January sounds wrong...
Peter Gfader
@Peter Gfader See: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute.aspx
Scoregraphic
A: 

If you want an auto incrementing number that updates each time a compilation is done, you can use VersionUpdater from a pre-build event. Your pre-build event can check the build configuration if you prefer so that the version number will only increment for a Release build (for example).