Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sync the SVN revision number with my ASP.NET web site?

Stack Overflow has a subversion version number at the bottom:

svn revision: 679

I want to use such automatic versioning with my .NET Web Site/Application, Windows Forms, WPD projects/solutions.

How do I implement this?

like image 242
Zack Peterson Avatar asked Aug 01 '08 18:08

Zack Peterson


People also ask

How do I find my svn revision number?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

What is revision number in svn?

As you saw in the section called “Revisions”, revision numbers in Subversion are pretty straightforward—integers that keep getting larger as you commit more changes to your versioned data.

How do I revise in svn?

"svn info --show-item revision" will give the current revision to which the current directory is updated.

What is base revision in svn?

BASE revision. The current base revision of a file or folder in your working copy. This is the revision the file or folder was in, when the last checkout, update or commit was run. The BASE revision is normally not equal to the HEAD revision.


4 Answers

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?

like image 147
saint_groceon Avatar answered Oct 18 '22 11:10

saint_groceon


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.

like image 28
Brad Wilson Avatar answered Oct 18 '22 09:10

Brad Wilson


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:$

like image 39
Nick Berardi Avatar answered Oct 18 '22 11:10

Nick Berardi


If you're using ASP.Net MVC (as StackOverflow does), I've written an easy to follow 3-step guide on how to automatically get and display the latest SVN revision. The guide was inspired by thinking to myself about this very question! :o)

like image 25
Andrew Avatar answered Oct 18 '22 10:10

Andrew