I\'m using TortoiseSVN and Visual Studio 2008. Is there any way to update my project\'s assemblyinfo.cs with svn\'s version in every build?
For example, 1.0.0.[svn\'
I do this in my build script:
<SvnInfo LocalPath=".">
<Output TaskParameter="Revision" PropertyName="BuildRev" />
</SvnInfo>
<FileUpdate Files="protobuf-net\Properties\AssemblyInfo.cs"
Regex='(\[\s*assembly:\s*AssemblyVersion\(\s*"[^\.]+\.[^\.]+)\.([^\.]+)(\.)([^\.]+)("\)\s*\])'
ReplacementText='$1.$2.$(BuildRev)$5' />
using the community build tasks. This essentially applies a regex to the AssemblyInfo.cs, replacing the current revision with the svn revision.
I created an SVN version plug-in for the Build Version Increment project (which is named in popester's answer). 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.
Yes, you can add a pre-build event that calls a script which
svn info
to extract the current revision number (if you do an update before, you can directly include the keyword $Revision$
in a file, check also this post);What I usually do is transform a AssemblyInfo.cs template when the project is built. The script is necessary to adapt the form of $Revision$ to the syntax of this file, unfortunately.
The interesting properties are (where the template strings are between '$'):
[assembly: AssemblyVersion("$v$.$build$.$Last Changed Rev$")]
[assembly: AssemblyFileVersion("$v$.$build$.$Last Changed Rev$")]
Edit: svn info
is part of the standard SVN client, not TortoiseSVN as pointed out in another post. Easy to install though. However, TortoiseSVN comes with SubWCRev.exe
which transforms a file with keyword substitution, so it would do the trick if you update your local copy.
How do you feel about a Visual Studio addin doing it?
You could use the $Rev$
svn keyword but that will give you the last revision of the file, I think you want to get the HEAD
revision number.
Give a look to this question:
You could use the SubWCRev tool which comes with TortoiseSVN (also available separately).
Either run it from a command line or use the COM-Object it offers.
The SubWCRev command line tool replaces keywords inside a file with information from your svn working copy. An example is shown in the docs.