How do I sync the SVN revision number with my ASP.NET web site?
Looks like Jeff is using CruiseControl.NET based on some leafing through the podcast transcripts. This seems to have automated deployment capabilities from source control to production. Might this be where the insertion is happening?
We do this with xUnit.net for our automated builds. We use CruiseControl.net
(and are trying out TeamCity). The MSBuild task that we run for continuous integration automatically changes the build number for us, so the resulting build ZIP file contains a properly versioned set of DLLs and EXEs.
Our MSBuild file contains a UsingTask reference for a DLL which does regular expression replacements: (you're welcome to use this DLL, as it's covered by the MS-PL license as well)
<UsingTask AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll" TaskName="CodePlex.MSBuildTasks.RegexReplace"/>
Next, we extract the build number, which is provided automatically by the CI system. You could also get your source control provider to provide the source revision number if you want, but we found the build # in the CI system was more useful, because not only can see the integration results by the CI build number, that also provides a link back to the changeset(s) which were included in the build.
<!-- Cascading attempts to find a build number --> <PropertyGroup Condition="'$(BuildNumber)' == ''"> <BuildNumber>$(BUILD_NUMBER)</BuildNumber> </PropertyGroup> <PropertyGroup Condition="'$(BuildNumber)' == ''"> <BuildNumber>$(ccnetlabel)</BuildNumber> </PropertyGroup> <PropertyGroup Condition="'$(BuildNumber)' == ''"> <BuildNumber>0</BuildNumber> </PropertyGroup>
(We try BUILD_NUMBER, which is from TeamCity, then ccnetlabel, which is from CC.net, and if neither is present, we default to 0, so that we can test the automated build script manually.)
Next, we have a task which sets the build number into a GlobalAssemblyInfo.cs file that we link into all of our projects:
<Target Name="SetVersionNumber"> <RegexReplace Pattern='AssemblyVersion\("(\d+\.\d+\.\d+)\.\d+"\)' Replacement='AssemblyVersion("$1.$(BuildNumber)")' Files='GlobalAssemblyInfo.cs'/> <Exec Command="attrib -r xunit.installer\App.manifest"/> </Target>
This find the AssemblyVersion attribute, and replaces the a.b.c.d version number with a.b.c.BuildNumber. We will usually leave the source checked into the tree with the first three parts of the builder number fixed, and the fourth at zero (f.e., today it's 1.0.2.0).
In your build process, make sure the SetVersionNumber task precedes your build task. At the end, we use our Zip task to zip up the build results so that we have a history of the binaries for every automated build.
You can do it by adding the following anywhere in your code
$Id:$
So for example @Jeff did:
<div id="svnrevision">svn revision: $Id:$</div>
and when checked in the server replaced $Id:$ with the current revision number. I also found this reference.
There is also $Date:$, $Rev:$, $Revision:$