SvnRevisionTool
Prints out the current SVN revision info of a working directory and automatically writes it into your .NET project for the build.
Archived content: This application is currently inactive and may be outdated or no longer maintained or functional.
This application has been replaced by NetRevisionTool. NetRevisionTool is an advancement of GitRevisionTool and SvnRevisionTool in a single program with new flexible features.
SvnRevisionTool is a small developer’s tool that prints out the current SVN revision info of a working directory. It can automatically write that revision information into your application’s code so that it's compiled right into it. This works for .NET solutions written in C# and VB.NET using the regular Visual Studio project structure.
Why?
Every bigger-than-small application has a version number that the user can query in some form of About dialog window. If you release often and don’t want to manage structured version numbers (like the ones of SvnRevisionTool itself), you might just use the SVN revision number or commit time as version number for your product. By automating the copying of that revision number into the application source code, you can avoid forgetting that update. Also, possible keyword replacing features of Subversion itself do not play very well with C#/VB.NET source code in creating a friendly version for that assembly. SvnRevisionTool is optimised for this scenario.
How can I use it?
Download the application and copy it to your Visual Studio solution directory. I like to put such little helpers in a subdirectory called “_scripts\bin” (see screenshot below), along with the PowerShell build framework. You should include that file into your SVN repository to keep it portable.
Then, open your project properties and switch to the build events page (see screenshot below). Add the following pre-build command (in one line):
if not defined FASTBUILD "$(SolutionDir)\_scripts\bin\SvnRevisionTool.exe" -ai "$(ProjectDir)"
Adapt the path if you used a subdirectory, as in the screenshot image. And add the following post-build command:
if not defined FASTBUILD "$(SolutionDir)\_scripts\bin\SvnRevisionTool.exe" -si "$(ProjectDir)"
Important: Set the post-build event to be executed always to ensure the modified source file is always restored correctly, also when your project doesn’t build correctly.
The condition with the environment variable “FASTBUILD” allows controlling the execution of GitRevisionTool for each project. For solutions with many (> 25) projects, you can set this environment variable (to any non-empty value) to prevent running GitRevisionTool. This decreases the build time. When using the PowerShell build framework, this variable is used as well and GitRevisionTool is started in multi project mode. If you do not need or want this feature and do not use the PowerShell build script, you can leave out the part if not defined FASTBUILD
to ensure that GitRevisionTool is always used.
Now open your project’s AssemblyInfo.cs or .vb file to configure your version number. That file is usually located in the “Properties” or “My Project” folder. The fourth segment of the version numbers in the AssemblyVersion
and AssemblyFileVersion
attributes is automatically replaced with the SVN revision, no matter what was there before. You can also look for the AssemblyInformationalVersion
attribute or add it if it’s not there yet, to have more advanced data inserted with a placeholder. Here’s an example:
[AssemblyFileVersion("1.0.0.0")]
[AssemblyInformationalVersion("MyApp r{commit}/{date:ymd-}")]
This results in the following, for example:
[AssemblyFileVersion("1.0.0.627")]
[AssemblyInformationalVersion("MyApp r627/2015-01-27")]
See the program’s output for the --help
parameter for all the details. There’s an option the scan a parent directory, or to require an unmodified working directory and other useful things waiting for you.
How does it do what it does?
SvnRevisionTool is called in the pre-build event with the parameter -a
. This is every time you build the project, before the compiler starts off. It will find your AssemblyInfo.cs or .vb file and replace the version number in the above mentioned attributes and the placeholder in the AssemblyInformationalVersion attribute to the actual revision data. Then Visual Studio includes that file in the compilation process. In the end, the -s
parameter restores the previously backed up file so that you (and Subversion) won’t see any changes to commit.
Important: For this to work, the AssemblyInfo file must not be opened in the Visual Studio editor during build, or the things that SvnRevisionTool writes into the file will be ignored for that build. So always close that file as long as you are tweaking your version string and test-building the project.
Compatibility:
I have a similar, newer tool that does the same for Git repositories and than can insert more data with placeholders: GitRevisionTool
Images
Note: The following screenshots are from the GitRevisionTool but basically describe the same.
Download
SvnRevisionTool_NET20.exe57 KiBProgram file, version 1.7.3, .NET 2.0
master.zipLatest source code directly from GitHub (GitRevisionTool and SvnRevisionTool)
There’s a public Git repository of GitRevisionTool on GitHub which also contains this project.
It doesn’t work?
SvnRevisionTool handles working copies up to version 1.6.x on its own. Newer format versions require an installed SVN program. This will be searched automatically in several locations, among them the installation directory of the Apache SVN client as well as TortoiseSVN (with selected CLI option).
SvnRevisionTool can only modify your C# or VB.NET project files. It won’t do anything but print the revision number for other project types. You may process that output with different tools.
This is a .NET application itself. It is targeted on the .NET 2.0 framework, so you should not have any problems on Windows Vista or later. If you use Visual Studio 2005 or later, you already have the .NET framework installed anyway.
Changes
Licence and terms of use
This software is released under the terms of the GNU GPL licence, version 3. You can find the detailed terms and conditions in the download or on the GNU website.
Statistic data
- Created on 2009-08-29, updated on 2015-01-26.
- Ca. 1 190 lines of code, estimated development costs: 1 200 - 4 800 €