I am using CCNET on a sample project with SVN as my source control. CCNET is configured to create a build on every check in. CCNET uses MSBuild to build the source code.
I would like to use the latest revision number to generate AssemblyInfo.cs
while compiling. How can I retrieve the latest revision from subversion and use the value in CCNET?
Edit: I'm not using NAnt - only MSBuild.
CruiseControl.Net 1.4.4 has now an Assembly Version Labeller, which generates version numbers compatible with .Net assembly properties.
In my project I have it configured as:
(Caveat:
assemblyVersionLabeller
won't start generating svn revision based labels until an actual commit-triggered build occurs.)and then consume this from my MSBuild projects with MSBuildCommunityTasks.AssemblyInfo :
For sake of completness, it's just as easy for projects using NAnt instead of MSBuild:
You have basically two options. Either you write a simple script that will start and parse output from
svn.exe info --revision HEAD
to obtain revision number (then generating AssemblyInfo.cs is pretty much straight forward) or just use plugin for CCNET. Here it is:
I prefer the first option because it's only roughly 20 lines of code:
I have written a NAnt build file that handles parsing SVN information and creating properties. I then use those property values for a variety of build tasks, including setting the label on the build. I use this target combined with the SVN Revision Labeller mentioned by lubos hasko with great results.
I found this project on google code. This is
CCNET
plugin to generate the label inCCNET
.The
DLL
is tested withCCNET 1.3
but it works withCCNET 1.4
for me. I'm successfully using this plugin to label my build.Now onto passing it to
MSBuild
...If you prefer doing it on the
MSBuild
side over theCCNet
config, looks like theMSBuild
Community Tasks extension'sSvnVersion
task might do the trick.I am currently "manually" doing it through a prebuild-exec Task, using my cmdnetsvnrev tool, but if someone knows a better ccnet-integrated way of doing it, i'd be happy to hear :-)
Found the above technique to auto-gen AssemblyInfo.cs using MSBuild. Will post sample shortly.
I'm not sure if this work with CCNET or not, but I've created an SVN version plug-in for the Build Version Increment project on CodePlex. This tool is pretty flexible and can be set to automatically create a version number for you using the svn revision. It doesn't require writing any code or editing xml, so yay!
I hope this is helps!
My approach is to use the aforementioned plugin for ccnet and a nant echo task to generate a
VersionInfo.cs
file containing nothing but the version attributes. I only have to include theVersionInfo.cs
file into the buildThe echo task simply outputs the string I give it to a file.
If there is a similar MSBuild task, you can use the same approach. Here's the small nant task I use:
Try this:
Please note that I'm not very intimate with MSBuild, so my script will probably not work out-of-the-box and need corrections...
Based on skolimas solution I updated the NAnt script to also update the AssemblyFileVersion. Thanks to skolima for the code!
No idea where I found this. But I found this on the internet "somewhere".
This updates all the AssemblyInfo.cs files before the build takes place.
Works like a charm. All my exe's and dll's show up as 1.2.3.333 (If "333" were the SVN revision at the time.) (And the original version in the AssemblyInfo.cs file was listed as "1.2.3.0")
$(ProjectDir) (Where my .sln file resides)
$(SVNToolPath) (points to svn.exe)
are my custom variables, their declarations/definitions are not defined below.
http://msbuildtasks.tigris.org/ and/or https://github.com/loresoft/msbuildtasks has the ( FileUpdate and SvnVersion ) tasks.
EDIT --------------------------------------------------
The above may start failing after your SVN revision number reaches 65534 or higher.
See:
Turn off warning CS1607
Here is the workaround.
The result of this should be:
In Windows/Explorer//File/Properties…….
Assembly Version will be 1.0.0.0.
File Version will be 1.0.0.333 if 333 is the SVN revision.
Be careful. The structure used for build numbers is only a short so you have a ceiling on how high your revision can go.
In our case, we've already exceeded the limit.
If you attempt to put in the build number 99.99.99.599999, the file version property will actually come out as 99.99.99.10175.