Click here to Skip to main content
13,507,150 members
Click here to Skip to main content
Add your own
alternative version


6 bookmarked
Posted 27 Apr 2013

Visual Studio 2010 Reading SVN Revision and Updating File and Product Version (Easy Way)

, 27 Apr 2013
Rate this:
Please Sign up or sign in to vote.
Easy Assembly Version reflecting SVN working revision


Visual Studio provides you two ways of updating your assembly, product and file. You can update them yourself, or let Visual Studio set the version to 1.0.*, meaning that the resulting version has nothing to relate with. In this tip, I will show a simple way to implement SVN revision number into file version.


This article implements the functions of SubWCRev.exe provided with TortoiseSVN. It is mainly aimed at Visual Studio 2010 with VisualSVN for C# projects, but the same process can be applied for other configurations.

Using the Code

"SubWCRev is a Windows console program which can be used to read the status of a Subversion working copy and optionally perform keyword substitution in a template file. This is often used as part of the build process as a means of incorporating working copy information into the object you are building. Typically it might be used to include the revision number in an “About” box." - This is the intended use, so let's make use of it.

SubWCRev is a command line application, so we can make use of it on the project's 'pre-build event command line'. We will go to read the working copy revision, update the file Assembly.cs, and then build our project.

In order for SubWCRev to update our Assembly.cs, we need to provide it with a template file, for this just create a copy of Assembly.cs and name it Assembly.tmpl. Now open Assembly.tmpl and replace the AssemblyVersion and AssemblyFileVersion with the following lines:

[assembly: AssemblyVersion("1.0.0.$WCREV$")]
[assembly: AssemblyFileVersion("1.0.0.$WCREV$")] 

Every occurrence of $WCREV$ will be replaced by the working copy revision number.

Now we can edit the pre-build event:

cd [TortoiseSVNInstallDir]\bin  
SubWCRev "WorkingCopyPath" "Assemby.tmpl Path" "Assembly.cs Path"  

If we just build the project now, the file Assembly.cs gets updated correctly, but the built assembly does not. The solution to this is very easy, open your .csproj file, copy this line:


And paste it right before the <PreBuildEvent> tag. Build your solution twice, and check that your FileVersion is 1.0.0.[SVNRevision].

Hope this helps some smaller developers with version control.

Points of Interest

While this will work OK for smaller projects, it still relies on the revision number being less than 65535.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180417.1 | Last Updated 28 Apr 2013
Article Copyright 2013 by prodrigues1990
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid