Automatically Adding SVN Revision Numbers to Assemblies

28 August 2009 (5 years ago)

Source code version control is one thing that no developer should ever live without. If you're working on some code that isn't in a version control system, stop what you're doing now and get yourself one!

There's no excuse - there are plenty of free ones available that are simple to install and use. My personal favourite is Subversion (SVN). The particular flavour I use is VisualSVN which has a simple server configuration system and a convenient Visual Studio plugin. If you're really new to version control, you could do a lot worse than to read the SVN book, too.

Exact revision numbers are a vital part of our quality control process. All bug reports are logged against a specific revision of our code. If a customer calls to report a bug we insist on having the exact revision number - 'Version 2.0.285'. Bug reported for 'Version 2' just aren't good enough and won't get logged in our bug list.

When bugs are fixed, the revision number which includes the fix is also logged. This gives us exact points in time where the bug existed, and where it was ultimately fixed. It also allows us to pinpoint what was done to fix the bug, and who did it.

Incrementing the revision number which gets displayed in your UI every time it changes is not something that should be done manually, though - it's far too easy to forget and is also completely unnecessary when you can quite easily automate it.

In our build process, we use the MSBuild Community Tasks project to automatically retrieve the revision number of the code from Subversion and add it to our assembly information. At runtime, we use reflection to read this information back out of the assembly for display to the user.

Configuring Your Build Process

First off, download and install the MSI package from the MSBuild Community Tasks website. You'll need to do this on every machine that will build your project.

Next, you'll need to modify the MSBuild script for your project - in other words - your Visual Studio project file (.vbproj or .csproj). You can do this either using your favourite text editor, or from within Visual Studio...

  1. Right-click on your project in the 'Solution Explorer' and select 'Unload Project'.
    If this option doesn't appear, you'll need to go to the Tools -> Options menu and tick the 'Always show solution' option under 'Projects and Solutions', first.
  2. Right-click on the newly 'unloaded' project and you will see an option to edit the project file.
  3. When you've finished your editing, you can right-click again and select 'Reload Project'.

If you look through this file, you will find some <Import Project="..."> statements. Add a new line and add a reference to the MSBuild Community Tasks targets:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

Directly under this, create a property group to contain the Major, Minor and Build numbers for your project. Note that the 'Revision' will get overwritten by the revision number from SVN:

<PropertyGroup>
  <Major>1</Major>
  <Minor>0</Minor>
  <Build>0</Build>
  <Revision>0</Revision>
</PropertyGroup>

The standard Visual Studio project template has a <Target Name=”BeforeBuild”> section which is commented out by default. Un-comment this and change it to the following:

<Target Name="BeforeBuild">
  <SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="C:\Program Files\VisualSVN\bin\">
    <Output TaskParameter="Revision" PropertyName="Revision" />
  </SvnVersion>
  <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)" />
  <AssemblyInfo CodeLanguage="VB"
                OutputFile="My Project\AssemblyInfo.vb"
                AssemblyTitle="My Assembly Title"
                AssemblyDescription="My Assembly Description"
                AssemblyCompany="My Company"
                AssemblyProduct="My Product"
                AssemblyCopyright="My Copyright"
                ComVisible="false"
                CLSCompliant="true"
                AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
                AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
                Condition="$(Revision) != 0" />
</Target>

There are obviously a few things in there that you'll want to change - particularly in the <AssemblyInfo> tag to make it more specific to your product. You may also need to change the 'ToolPath' attribute of the <SvnVersion> tag to the location of your command line SVN tool.

Once you've made these changes, reload your project and try a build. All being well the resulting DLL will include the correct version number.

Displaying the Revision Number in your UI

The final step is to get your revision number showing in your UI for all to see. Luckily, reflection comes to the rescue and allows you to retrieve your entire version number in this (rather long) single line of code:

VersionNo = System.Reflection.Assembly.GetExecutingAssembly().GetName.Version.ToString

Then, proudly display this value in a label on your Windows form, or squirt it out in your HTML for all to see!

Comments

????? ?????????????

22 May 2012
(2 years ago)
Avatar

---  ????? ?????????????  ---

???????????? ??????

30 May 2012
(2 years ago)
Avatar

---  ????????????? ??????????? ---

???? ???????? ???????

1 June 2012
(2 years ago)
Avatar

---  ?????????? ??????????? ????? ---

?????? prestashop

7 June 2012
(2 years ago)
Avatar

---  ?????? prestashop ---

Pharmc297

10 June 2012
(2 years ago)
Avatar

Hello! bgfckae interesting bgfckae site! I'm really like it! Very, very bgfckae good!

??????? ????? ??????

18 June 2012
(2 years ago)
Avatar

---  ??????? ????? ? ??????? ---

Pharme812

20 June 2012
(2 years ago)
Avatar

Hello! aeekagd interesting aeekagd site! I'm really like it! Very, very aeekagd good!

Pharmc765

20 June 2012
(2 years ago)
Avatar

Very nice site!

Pharmb903

20 June 2012
(2 years ago)
Avatar

Hello! eceecad interesting eceecad site! I'm really like it! Very, very eceecad good!

viagra

22 June 2012
(2 years ago)
Avatar

http://comprar-cialis-generico.net/ comprar cialis espana    
http://comprarviagragenerico-es.net/ viagra sin receta  
http://viagrakaufengenerika.net/ billige viagra

Pharmc516

24 June 2012
(2 years ago)
Avatar

Hello! bbkecdf interesting bbkecdf site! I'm really like it! Very, very bbkecdf good!

Pharma410

24 June 2012
(2 years ago)
Avatar

Very nice site!

Pharme862

24 June 2012
(2 years ago)
Avatar

Hello! dbdgcde interesting dbdgcde site! I'm really like it! Very, very dbdgcde good!

?????? ???? ? ??????? ?????

25 June 2012
(2 years ago)
Avatar

---  ????????????? ?????? ????  ---

Pharmd838

29 June 2012
(2 years ago)
Avatar

Hello! gedafae interesting gedafae site! I'm really like it! Very, very gedafae good!

???????????? ?? ?????

10 July 2012
(2 years ago)
Avatar

---  ???????????? ?? ???????? ?????  ---

???????????? ?? ?????

10 July 2012
(2 years ago)
Avatar

---  ???????????? ?? ???????? ?????  ---

????????? ?????

10 July 2012
(2 years ago)
Avatar

---  ??????? ??????  ---

??????????

12 July 2012
(2 years ago)
Avatar

---  ??????????  ---

RAR Recovery ToolBox

14 July 2012
(2 years ago)
Avatar

---  ?????????????? ?????? ????? ??????????????  ---

Pharmf30

14 July 2012
(2 years ago)
Avatar

Hello! ecgdaag interesting ecgdaag site! I'm really like it! Very, very ecgdaag good!

Pharma820

14 July 2012
(2 years ago)
Avatar

Very nice site!

Pharmf434

14 July 2012
(2 years ago)
Avatar

Hello! fdedfbk interesting fdedfbk site! I'm really like it! Very, very fdedfbk good!

?????????? ?????

15 July 2012
(2 years ago)
Avatar

---  ??????? ? ???????  ---

??????? ? ????? ? ?????

15 July 2012
(2 years ago)
Avatar

---  ??????? ? ???????  ---

????????????? ?????????????

15 July 2012
(2 years ago)
Avatar

---  ????????????? ????????????? ??  ---

????????????? ????????????? ??

15 July 2012
(2 years ago)
Avatar

---  ????????????? ????????????? ??  ---

cialis

29 August 2012
(2 years ago)
Avatar

nice site)
http://comprarecialisgenericoit.net/ prezzo cialis
http://comprarcialisgenericoes.net/cialis
http://bestellen-cialis-generika.net/ cialis generika

Pharma714

22 November 2012
(1 year ago)
Avatar

Hello! defffgd interesting defffgd site! I'm really like it! Very, very defffgd good!

Pharme943

22 November 2012
(1 year ago)
Avatar

Very nice site!

Pharme632

22 November 2012
(1 year ago)
Avatar

Hello! aeeafec interesting aeeafec site! I'm really like it! Very, very aeeafec good!

???????????? ??????

1 December 2012
(1 year ago)
Avatar

--- ???????????? ?????? ---

Pharmf223

12 December 2012
(1 year ago)
Avatar

Hello! ddbeccg interesting ddbeccg site! I'm really like it! Very, very ddbeccg good!

Pharmf788

12 December 2012
(1 year ago)
Avatar

Hello! fkdegee interesting fkdegee site! I'm really like it! Very, very fkdegee good!

hejrbtba

31 March 2013
(1 year ago)
Avatar


Zhao Mingyang is A Erbin strong say to won't abandon player of real moral character all right
7 days afternoon 16 when 05 minutes, Dalian A ErbinTeam general arms sends Jinan, begin annual the brigade of field of the first guest. PresidentZhao MingyangCome to A Erbin base afternoon at 6 days, for be about to the team of go out for a battle is strong row, he encourages all player not to suffer the outside to disturb, believe oneself [url=http://www.bindaaspoll.com/classicnikeshox.aspx]nike shox r4 sale[/url] have actual strength to play good game, opening bureau phase gnash one's teeth to overcome difficulty, grab cent more. The player of original real moral character that he comforts this sports season to fail to turn into A Erbin team at the same time, "League matches does not have the player of the name on the newspaper this year, I won't abandon everybody, these players should insist to train well. These players should insist to train well..   Zhao Mingyang of president of A Erbin group is away on official business to just return Dalian to come to base afternoon yesterday, visit be about to all player of go out for a battle. League matches has not begun, a Erbin team experienced the effect that changes player of Shuai Fengbo, real moral character to cannot turn to wait for incident, zhao Mingyang says: "A lot of problems of the outside were not solved, affected a lot of plans. League matches does not have the player of the name on the newspaper this year, I won't abandon everybody, these players should insist to train well. " he at the same time incentive player people say: "I have hope to everybody, you also should have hope to oneself. League matches is very endless, the result of the match can get the influence of a lot of elements, hope everybody has adjusted him in the match. Hope everybody has adjusted him in the match..   This Saturday, a Erbin team challenges guest field Lu Neng, zhao Mingyang cannot be team to aid to the spot because of firm work blast, he tells a player people, "League matches the first level is very important, very difficult also. Leave bureau dozen bad, annual is very difficult. Ate namely last year this is deficient, second half of the year is hit so well, half Cheng champion, also did not enter finally inferior coronal. Hope everybody, the bureau is much bite gnash one's teeth, grab cent more. Grab cent more..   Know a player people care very much advocate the problem of handsome person selected, zhao Mingyang says: "The bishop is experienced, the person that recommends to me is very much, candidate is sufficient now have 50 people. I also am done not have too anxious, this needs to consider well, cannot too hurried. The style that episcopal practice must accord with A Erbin and make a way, is not to come a person, concede points team gets used to him afresh. " (Sohu sports)(responsibility edits: Happy-go-lucky)

kazino960

17 April 2013
(1 year ago)
Avatar

?????? ?????? ?????? ??? ??????????? ? ??? [url=http://complirealcuchobird.pochta.ru/new86.html]??????? ???????? ?????? ?????? ????????? ?????[/url] ?????? ?????? ?????????, ?????? ?????? crystal palace hotel.

Carlota

19 July 2014
(3 months ago)
Avatar

Hiya very nice site!! Guy .. Beautiful .. Wonderful .. I will bookmark
your blog and take the feeds also? I'm glad to search out so many helpful information here within the publish,
we need develop extra strategies in this regard, thank you for
sharing. . . . . .

cosmetic surgery website design

17 September 2014
(1 month ago)
Avatar

WOW just what I was searching for. Came here by searching for creative
marketing web designs

ronniedvhl.bravesites.com

17 September 2014
(1 month ago)
Avatar

Nice blog here! Also your site loads up fast! What host
are you using? Can I get your affiliate link to your host?
I wish my site loaded up as quickly as yours lol

web and marketing

18 September 2014
(1 month ago)
Avatar

Do you mind if I quote a couple of your articles
as long as I provide credit and sources back to your
site? My website is in the very same niche as yours and my
users would definitely benefit from some of the information you provide
here. Please let me know if this okay with you. Cheers!

Charlesgon

23 October 2014
(1 week ago)
Avatar

http://acheterviagragneriquefrance50mg.com/ acheter viagra
http://acquistareviagragenericosenzaricetta.com/ prezzo viagra
http://comprarviagragenericobarato.com/ comprar viagra
http://viagragenerikakaufendeutschland.net/ viagra kaufen

Leave a Comment