views:

151

answers:

4

I use the assembly information version number - and advance it manually through the VS 2008.

Is there a way to advance the minor version number automatically each time I Build the solution ?

+1  A: 

Visual studio have a build-in mecanism for that:

inside AssemblyInfo.cs, change the settings by this one:

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

Asterisk sign instructs Visual Studio to assign on each build a version 1.0.d.s, where d is the number of days since February 1, 2000, and s is the number of seconds since midnight/2.

EDIT:

Take a look at this webpage: http://www.codeproject.com/KB/dotnet/ManagingAssemblyVersions.aspx there is many information about: how to manage the version number.

Matthieu
10x, how can I tell which is the current number / have a "sid" - meaning - if the project is in number 55 and I want it to start automatically from 56 ?(or start from zero after a magor version number change ?)
Dani
I've tried using * in that field - the ide doesn't allow it.
Dani
If i remember correctly, the first generated number will be generated in function of the date, and the second one with a build number.So you will get number like 1.0.4245.51002
Matthieu
Well, it works (vote up), but can't I control the start number ? I got: 1.0.0.31411 and after 1 build it went to 31485 !so it doesn't even jump sequentially....
Dani
A: 

IIRC In your solution explorer, click on "Show all files", I believe it's the third one near the top of that window.

(double)click on "My Project."

Next, double-click on "AssemblyInfo.vb"

In the code editor, scroll down until you've reached the bottom.

Comment out

Replace

<Assembly: AssemblyVersion("1.0.0.0")>

with

<Assembly: AssemblyVersion("1.*.0")>

Click 'Save'.

Then you're done!

Pace
yeah,but that doesn't nicely advance the build number - it just grabs the current time and date adn sticks it in there, so your build numbers look something like 1.0.21643.23849 and so forth....
marc_s
Thanks for that, ill make a note. I remember one of my co-workers mentioning it one time.
Pace
+2  A: 

I used this MSBuild Task to auto-increment my build numbers - requires a few manual modifications in your *.csproj or *.vbproj files, but it works quite flawlessly, and is quite flexible, too.

marc_s
I think this targets what I need better, it will take me some time to test it, but it looks right ! thanks !
Dani
This is a little problem, I am using a svn controlled environment which locks the files if I don't check them out.using this solution makes me lock the assembly.cs in order to build.I guess there is no way to avoid this... but it takes the fun out of the solution...
Dani
A: 

One flexible option is to create a T4 template with version numbering scheme and reference a .cs file that Visual Studio generates from it. An example of such template:

<#@ template language="C#" #> // // This code was generated by a tool. Any changes made manually will be lost // the next time this code is regenerated. //

using System.Reflection;

[assembly: AssemblyVersion("1.0.1.<#= this.RevisionNumber #>")] [assembly: AssemblyFileVersion("1.0.1.<#= this.RevisionNumber #>")] <#+ int RevisionNumber = (int)(DateTime.UtcNow - new DateTime(2010,1,1)).TotalDays;

>

In this example revision number is set to the number of days since January 1st, 2010. But you can provide any custom numbering scheme, because it's plain C#.

I wrote a blog post which explains this technique in more details:

Vagif Abilov
Thanks, I'll check your blog to understand this technique.
Dani