How to automatically insert SVN Version number on a webpage(assembly)?

January 28, 2011 PGS Team


I will try shortly and easily to describe, how to add automatically the SVN version number information into a ASP.NET Web Page.

Of course first thought was just to generate a text file(using svnversion command) with the version information, so why not?
Because it can be easily updated “by hand” after a deploy, or it can get lost while deploying/copying to an external server, or even not updated properly.

Basing on the solution found on Florent Clairambault Blog here, I thought why not integrate it into the my Web Deployment Project? Let’s give it a chance 🙂

So I have just followed the steps in the example Post and updated my WDProj file:

  1. Downloaded the MSBuildCommunityTaskschecked
  2. Make sure your “svn.exe” binary is in C:program filessubversionbin? – No isn’t but it works 🙂 checked
  3. Use the example code in your project file – checked

Of course it compiled successfully, but the deployed version was always one version behind…why?
I’m using AspNet Merge to merge my resulting DDLs into one “big” DLL, because having a Web Page it’s easier to replace on a external environment.
The build-in merge tool takes the AssemblyInfo found in [proj_dir]PropertiesAssemblyInfo.cs, which is updated by the AssemblyInfo Task.
But the Web Deployment Project first makes a prebuild and then executes the Task BeforeBuild.. hmm, so the change of the AssemblyInfo.cs is to late…

But fortunately, the Merge Task allows do define extra attributes for the AssemblyInfo, great!
All required information about the AssemblyInfo can be found here.

So I have made a change in my “BeforeMerge” task in my Wdproj like the one below:

<Target Name="BeforeMerge" >

<Message Text=”** Running BeforeMerge *****” Importance=”High” />


<AssemblyAttributes Include=”AssemblyVersion”>

<AssebmlyAttributes Include=”AssemblyFileVersion”>

<AssebmlyAttributes Include=”AssemblyInformationalVersion”>

<AssebmlyAttributes Include=”AssemblyCompany”>



After the merge task I have got the following output information:
***** Running BeforeBuild *****
Running Version...
Running SvnVersion...
Running AssemblyInfo...
***** Running BeforeMerge *****
Generating AssemblyInfo.
Setting [assembly: AssemblyVersion("1.0.9723.11")]
Successfully generated AssemblyInfo file.
Running aspnet_merge.exe.
Successfully merged 'objDebugTempBuildDir'.

Last thing was just to display the info on the Web Page,using also the example source code:
public static String Version { get {
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
} }


Last posts