Jcf
Jcf

Reputation: 201

How to get TortoiseSVN 1.7.x revision programmatically?

Is there any way to get current revision number of TortoiseSVN 1.7 local working copy programmatically? I want to use it to set version of my software installer.

Upvotes: 3

Views: 3667

Answers (5)

Tillito
Tillito

Reputation: 7868

After some research, this was the easiest way for me:

  1. Within C#, run SubWCRev.exe (which is installed with Tortoise SVN)
  2. Read the revision number form its output

1st part: See http://blogs.msdn.com/b/ericwhite/archive/2008/08/07/running-an-executable-and-collecting-the-output.aspx

2nd part:

string exe = @"C:\Program Files\TortoiseSVN\bin\SubWCRev.exe";
string projectPath = @"C:\MyProject";
RunResults runResults = Program.RunExecutable(exe, projectPath, projectPath);
string lines = runResults.Output.ToString();

Regex regex = new Regex(@"\D*Updated to revision ([0-9]+)\D*");

Match match = regex.Match(lines);
int revision = -1;
if (match.Success)
{
    revision = int.Parse(match.Groups[1].Value);
}

No idea if this is the best solution. For me, it was the least complicated. I had tried http://netpl.blogspot.de/2011/10/reading-revision-number-of-local-copy.html which did not work. The svn Version is not included in my Sqlite Database and therefore can't be read from any of the regex proposed on the article.

Upvotes: 1

Dmitriy Konovalov
Dmitriy Konovalov

Reputation: 1817

You can get svn info by using console tool SubWCRev.exe directry: (Use Subversion Revision Numbers in your Visual Studio Projects)[http://www.codeproject.com/KB/architecture/svn_visual_studio.aspx].

Another way to get svn info is to use special msbuild task avaliable in (MSBuild Community Tasks)[http://msbuildtasks.tigris.org/]. For example, you can update your AssemlyInfo files with fresh data every time you build your project. Check out this article: Insert SVN version and Build number in your C# AssemblyInfo file.

For example, later you can embed your AssemblyInfo data into wix project How to insert an assembly version number into a WiX script at build time.

Upvotes: 1

Tigran
Tigran

Reputation: 62265

Remember that Tortoise is nothing else the UI client for Subversion project.

There is a guide for automatton of Tortoise client from command line: Automating Tortoise from command line

If it's not enough, just install any Subversion client available on internet, for example: SlikSvn, or just original one and

  1. Move to working copy directory

  2. After run from command line svn info --xml > log.xml. You will all information you need in XML format in log.xml.

    Or

    Just run svn info $WorkingCopyPath$ --xml > log.xml

Hope this helps

Upvotes: 3

Lazy Badger
Lazy Badger

Reputation: 97375

Don't reinvent the wheel!

Instead of dealing with svnversion or svn info and parsing results, you have with TSVN SubWCRev command-line tool, which allow to use (versioned) template file, in which some changeable repository-related data is defined as SubWCRev-keywords and your build-tool (or you, by hand) just have to run SubWCRev with needed template-file on your WC and get versioninfo for installer in result-file

Upvotes: 4

Robert
Robert

Reputation: 42799

TortoiseSVN comes with the command-line tool svnversion.exe. This tiny little tool just prints out the revision number of a local working copy. If you don't specify a working copy directory it checks the current directory if it is a working copy (if not it outputs "exported") and if yes it prints out th revision number and the flag(s) - e.g. M for modified.

Upvotes: 2

Related Questions