How can you automatically import the latest build/revision number in subversion?
The goal would be to have that number visible on your webpage footer like SO does.
The svnversion command is the correct way to do this. It outputs the revision number your entire working copy is at, or a range of revisions if your working copy is mixed (e.g. some directories are up to date and some aren't). It will also indicate if the working copy has local modifications. For example, in a rather unclean working directory:
$ svnversion
662:738M
The $Revision$ keyword doesn't do what you want: it only changes when the containing file does. The Subversion book gives more detail. The "svn info" command also doesn't do what you want, as it only tells you the state of your current directory, ignoring the state of any subdirectories. In the same working tree as the previous example, I had some subdirectories which were newer than the directory I was in, but "svn info" doesn't notice:
$ svn info
... snip ...
Revision: 662
It's easy to incorporate svnversion into your build process, so that each build gets the revision number in some runtime-accessible form. For a Java project, for example, I had our makefile dump the svnversion output into a .properties file.
I use the MSBuild Community Tasks project which has a tool to retrieve the SVN revision number and add it to your AssemblyInfo.vb. You can then use reflection to retrieve this string to display it in your UI.
Here's a full blog post with instructions.
I created an SVN version plug-in for the Build Version Increment project on CodePlex. This SVN plug-in will pull the latest change revision number from your working copy and allow you to use that in your version number, which should accomplish exactly what you're trying to do. Build Version Increment is pretty flexible and will allow you to set up how the versioning is done in a number of ways.
BVI only works with Visual Studio, but since you're using Asp.Net, that won't be a problem. It doesn't require writing any code or editing xml, so yay!
You don't say what programming language/framework you're using. Here's how to do it in Python using PySVN
import pysvn
repo = REPOSITORY_LOCATION
rev = pysvn.Revision( pysvn.opt_revision_kind.head )
client = pysvn.Client()
info = client.info2(repo,revision=rev,recurse=False)
revno = info[0][1].rev.number # revision number as an integer
Add svn:keywords to the SVN properties of the source file:
svn:keywords Revision
Then in the source file include:
private const string REVISION = "$Revision$";
The revision will be updated with the revision number at the next commit to (e.g.) "$Revision: 4455$"
. You can parse this string to extract just the revision number.
if you're using svnant, you can use wcVersion, which duplicates svnveresion and returns digestible values. see: http://subclipse.tigris.org/svnant/svn.html#wcVersion