2

I'm developing a C# .net application in visual studio that I'm version controlling with tortoise SVN.

My question is this: Is there a way i can link the assembly version of my main project eg:

    [assembly: AssemblyVersion("2.2.3.4")]

To the revision number in tortoise SVN.

In such a way that i can check out revision 2.2.3.4 directly instead of checking out eg. revision 52 (or whatever revision equals version 2.2.3.4).

That would make it easier for me when I'm trying to get a specific version of my program as i don't have to figure out what SVN revision number equals the software version number I'm looking for.

Thanks

Sigurd V
  • 5,077
  • 4
  • 18
  • 27
  • You could set the last number of the version to the revision number. So 2.2.3.1463 would point to revision 1463. But I don't know the max limit of the version number. In NAnt there's a command to manipulate the AssemblyInfo.cs, very handy to that for the case you have NAnt and a build server... – this.myself Jul 18 '13 at 06:15

2 Answers2

6

Add Version.cs.tpl file to your project with the content like this:

namespace Versioning
{
    public static class VersionInfo
    {
        public const string Version = "2.2.3.$WCREV$";  
    }
}

Add pre-build event for your project:

SubWCRev.exe "$(SolutionDir)\" "$(ProjectDir)Version.cs.tpl" "$(ProjectDir)Version.cs" -f

Build the project. Version.cs will be created in project's folder, add it to project. Now you may modify your AssemplyInfo.cs like this:

[assembly: AssemblyVersion(Versioning.VersionInfo.Version)]

SubWCRev.exe is a tool in Tortoise program folder (http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html). It should be accessible (e.g. set in PATH variable). Now each time revision of your project changes, it will be reflected in version of your assembly after build.

Seems that this also applicable to your post: Linking Tortoise SVN revision number to assembly version

Community
  • 1
  • 1
the_virt
  • 707
  • 4
  • 10
  • +1 This is a great solution, only issue is if the dev doesn't build or get latest before checking in. – Matthew Jan 17 '14 at 00:25
  • Resulted Version.cs is not supposed to be checked in, it's generated file. When you build you get the assemblies stamped with your current checkout revision, that's fair enough... – the_virt Jan 24 '14 at 11:03
  • @Matthew: SubWCVer's -m option errors out if the working copy has mixed revisions. I guess that can be used to handle the problem you mentioned. – Aelian Jun 11 '14 at 18:59
0

Why not name the branch using the version number?

You could use tags and name each tag with the version ... but tagging is mainly for signed-off branches.

Or, you could use a commit hook to append the version number to each commit message and search TortoiseSVN's log for that, and check out from there.

Sameer Singh
  • 1,358
  • 1
  • 19
  • 47