Including SVN Revision in Your .NET Assembly Versioning
In the world of software development, maintaining version control is crucial. For those using Subversion (SVN) as their version control system, being able to include the SVN repository revision number in the version string of a .NET assembly can enhance traceability and debugging ease. If you’ve been asking yourself, “Is there a way to do this without third-party tools like CC.NET?”, the answer is a resounding yes.
The Problem: Versioning Without Extra Tools
You may have encountered situations where you want your version string to not just reflect major and minor version numbers, but also the SVN revision number. A typical target version format you might consider looks like this:
Major.Minor.SVNRev
Unfortunately, finding a straightforward method to achieve this in .NET without additional software can be a challenge, especially if you have previously done something similar in languages like C or C++. In C/C++, this could be accomplished using a build script that updated a header file with the version number.
The Solution: Using SubWCRev
One effective way to incorporate the SVN revision number into your .NET assembly versioning is through SubWCRev, a utility included with TortoiseSVN. SubWCRev reads SVN keywords from your files and replaces them with the appropriate revision info during the build process.
Step-by-Step Guide to Implementing SubWCRev
-
Download and Configure TortoiseSVN:
- Start by downloading TortoiseSVN if you haven’t already.
- Install it on your machine to access the bundled SubWCRev utility.
-
Setup Your AssemblyInfo.cs:
- Open your
AssemblyInfo.cs
file; this file typically contains your assembly’s version information. - Add placeholders where the version numbers will be replaced by
SubWCRev
.
Example:
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0.0")]
- Open your
-
Create a Template File:
- Create a new text file (e.g.,
VersionInfo.txt
) and structure it to define how the version info should be filled in. - Use placeholders for the revision number.
Example of
VersionInfo.txt
:[assembly: AssemblyVersion("${VersionNumber}.0")] [assembly: AssemblyFileVersion("${VersionNumber}.0")] [assembly: AssemblyInformationalVersion("${VersionNumber}.${Revision}")]
- Create a new text file (e.g.,
-
Run SubWCRev:
- Use the SubWCRev command to replace the placeholders in your
VersionInfo.txt
file with actual version numbers from your SVN repository. - This can typically be done via a command line or included in your build scripts.
- Use the SubWCRev command to replace the placeholders in your
-
Build Your Project:
- When building your project, SubWCRev will generate a new
AssemblyInfo.cs
with the version populated with your SVN revision.
- When building your project, SubWCRev will generate a new
Conclusion
By incorporating SubWCRev into your .NET project workflow, you can easily ensure that your assembly’s version string includes the SVN revision number, all without needing to depend on external software like CC.NET. This approach not only makes your versioning more informative but also keeps it straightforward and manageable.
Now that you know how to include the SVN revision number
in your .NET assembly versioning, give it a try in your next project, and you’ll appreciate the clarity it brings.