<p>Stack Overflow has a subversion version number at the bottom:</p>

<blockquote>
  <p>svn revision: 679</p>
</blockquote>

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

<p>How do I implement this?</p>

[{'answer_id': 166, 'author': 'Nick Berardi', 'author_id': 17, 'author_profile': 'https://Stackoverflow.com/users/17', 'pm_score': 5, 'selected': False, 'text': '<p>You can do it by adding the following anywhere in your code </p>\n\n<pre><code>$Id:$\n</code></pre>\n\n<p>So for example @Jeff did:</p>\n\n<pre><code>&lt;div id="svnrevision"&gt;svn revision: $Id:$&lt;/div&gt;\n</code></pre>\n\n<p>and when checked in the server replaced $Id:$ with the current revision number.  I also <a href="http://www.compuphase.com/svnrev.htm" rel="nofollow noreferrer">found this reference</a>.</p>\n\n<p>There is also <strong>$Date:$</strong>, <strong>$Rev:$</strong>, <strong>$Revision:$</strong></p>\n'}, {'answer_id': 170, 'author': 'saint_groceon', 'author_id': 59, 'author_profile': 'https://Stackoverflow.com/users/59', 'pm_score': 6, 'selected': True, 'text': '<p>Looks like Jeff is using <a href="https://web.archive.org/web/20090130045625/http://confluence.public.thoughtworks.org/display/CCNET/What+is+CruiseControl.NET" rel="nofollow noreferrer">CruiseControl.NET</a> 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?</p>\n'}, {'answer_id': 9391, 'author': 'James Pogran', 'author_id': 1083, 'author_profile': 'https://Stackoverflow.com/users/1083', 'pm_score': 3, 'selected': False, 'text': '<p><code>$rev</code> and others like it are revisions for the individual files, so they won\'t change unless the file changes. The number on the webpage is (most likely, I\'m assuming here) the svn revision number for the whole project. That is different than the file revisions, which others have been pointing to.</p>\n\n<p>In this case I assume that CCNET is pulling the revision number of the project and rewriting a part of the webpage with that number. Any CI solution should be able to do this, set this up myself with CCNET and Teamcity (although not webpages, but automatic versioning of deployment/assembly versions).</p>\n\n<p>In order for you to do this, use a CI solution that supports it, or use your build process (MSbuild/Nant) to store that version and write it to the files before "deploying" it.</p>\n'}, {'answer_id': 13258, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 5, 'selected': False, 'text': '<p>We do this with <a href="http://www.codeplex.com/xunit" rel="noreferrer">xUnit.net</a> for our automated builds. We use <code>CruiseControl.net</code> (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.</p>\n\n<p>Our <a href="http://www.codeplex.com/xunit/SourceControl/FileView.aspx?itemId=115610&amp;changeSetId=20735" rel="noreferrer">MSBuild file</a> 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)</p>\n\n<pre>\n  &lt;UsingTask\n     AssemblyFile="3rdParty\\CodePlex.MSBuildTasks.dll"\n     TaskName="CodePlex.MSBuildTasks.RegexReplace"/&gt;\n</pre>\n\n<p>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.</p>\n\n<pre>\n &lt;!-- Cascading attempts to find a build number -->\n\n &lt;PropertyGroup Condition="\'$(BuildNumber)\' == \'\'">\n   &lt;BuildNumber>$(BUILD_NUMBER)&lt;/BuildNumber>\n &lt;/PropertyGroup>\n &lt;PropertyGroup Condition="\'$(BuildNumber)\' == \'\'">\n   &lt;BuildNumber>$(ccnetlabel)&lt;/BuildNumber>\n &lt;/PropertyGroup>\n &lt;PropertyGroup Condition="\'$(BuildNumber)\' == \'\'">\n   &lt;BuildNumber>0&lt;/BuildNumber>\n &lt;/PropertyGroup>\n</pre>\n\n<p>(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.)</p>\n\n<p>Next, we have a task which sets the build number into a GlobalAssemblyInfo.cs file that we link into all of our projects:</p>\n\n<pre>\n &lt;Target Name="SetVersionNumber">\n   &lt;RegexReplace\n       Pattern=\'AssemblyVersion\\("(\\d+\\.\\d+\\.\\d+)\\.\\d+"\\)\'\n       Replacement=\'AssemblyVersion("$1.$(BuildNumber)")\'\n       Files=\'GlobalAssemblyInfo.cs\'/>\n   &lt;Exec Command="attrib -r xunit.installer\\App.manifest"/>\n &lt;/Target>\n</pre>\n\n<p>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).</p>\n\n<p>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.</p>\n'}, {'answer_id': 65747, 'author': 'nickf', 'author_id': 9021, 'author_profile': 'https://Stackoverflow.com/users/9021', 'pm_score': 3, 'selected': False, 'text': '<p>@Balloon\nIf you are using TortoiseSVN, you can use the packaged <a href="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html" rel="noreferrer">SubWCRev</a> program. It queries a working copy and tells you just the highest revision number. Admittedly, this seems to be a client-side approach to a server-side problem, but since it\'s a nice command line program, you should be able to capture its output for use fairly easily.</p>\n'}, {'answer_id': 157243, 'author': 'jan', 'author_id': 1163, 'author_profile': 'https://Stackoverflow.com/users/1163', 'pm_score': 3, 'selected': False, 'text': '<p>To add to @BradWilson\'s answer: <em>&quot;You could also get your source control provider to provide the source revision number if you want&quot;</em></p>\n<p>To connect Subversion and MSBuild:\n<a href="http://msbuildtasks.tigris.org/" rel="nofollow noreferrer">MSBuild Community Tasks Project</a></p>\n'}, {'answer_id': 374153, 'author': 'Andrew', 'author_id': 5662, 'author_profile': 'https://Stackoverflow.com/users/5662', 'pm_score': 4, 'selected': False, 'text': '<p>If you\'re using <code>ASP.Net MVC</code> (as StackOverflow does), I\'ve written an <a href="http://www.fatlemon.co.uk/2008/12/automatic-svn-revision-numbering-in-aspnet-mvc/" rel="nofollow noreferrer" title="Automatic SVN revision numbering in ASP.Net MVC - www.fatlemon.co.uk">easy to follow 3-step guide on how to automatically get and display the latest SVN revision</a>.  The guide was inspired by thinking to myself about this very question!  :o)</p>\n'}]
['https://Stackoverflow.com/questions/163', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/83/']