views:

98

answers:

1

I'm trying to setup my VisualStudio project to set the assembly version based on the latest subversion revision number as described on this page. But the version number always seems to lag one revision.

I've split out the assembly version attribute into a separate file, VersionInfo.cs, that is updated with a pre build event.

I'm using the following code to display the version number in the title of my form:

System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly();
this.Text = "My Program Version: " + assem.GetName().Version.ToString();

Here's an walk through of what's happening.

  1. I commit my project so that it is at the latest revision.

  2. Using TortiseSVN I use show log to see that I'm at revision 55

  3. I build my solution.

  4. I then open VersionInfo.cs and see that the pre-build event correctly overwrote this file as

    [assembly: System.Reflection.AssemblyVersion("0.1.55.*")]

  5. Yet when I run the program the title bar displays and old version 0.1.52.20486

  6. Next I open the project file in notepad, and change something, such as adding a blank line, and then save the file.

  7. VisualStudio shows a notification that the project file has changed and prompts me to reload the project which I accept

  8. Now when I build and run the program the form shows version 0.1.55.20645

  9. I make a change to something in the project, and commit to SubVersion.

  10. TortiseSVN confirms my working copy is now at revision 56.

  11. I build my project and VersionInfo.cs is correctly updated to

    [assembly: System.Reflection.AssemblyVersion("0.1.56.*")]

  12. I try running the application again and the forms title shows 0.1.55.20750 rather then 0.1.56.xxxxxx

Also I've noticed that even if I rebuild/rerun my application the build number (the last number in the version number) is also not updated. It was my understanding that the asterisk would be replaced my a new number at each build.

Any one have any idea what's going on?

A: 

When you checkin a file, the revision number is incremented as you know. The problem is, you do not know what that revision number will be when you checkin - you only find out after checkin.

So, if you take the latest revision number, build your project, then checkin - the number used will always be out of date. What you really want is to be able to checkin, then get the revnum of the commit you've just performed, and then build your project with the correct version number.

Obviously this is not possible.

There is a way round it - use a CI system that builds your project immediately after checkin (through a post-commit hook). These will checkout the latest version you've just added, update your version.cs file, then build. The disadvantage is that your version.cs file will never contain the correct version number (unless the CI system then checks just it in again)

gbjbaanb