How to access the current Subversion build number?

前端 未结 16 2183
刺人心
刺人心 2020-11-27 05:43

How can you automatically import the latest build/revision number in subversion?

The goal would be to have that number visible on your webpage footer like SO does.

16条回答
  •  生来不讨喜
    2020-11-27 06:09

    You want the Subversion info subcommand, as follows:

    $ svn info .
    Path: .
    URL: http://trac-hacks.org/svn/tracdeveloperplugin/trunk
    Repository Root: http://trac-hacks.org/svn
    Repository UUID: 7322e99d-02ea-0310-aa39-e9a107903beb
    Revision: 4190
    Node Kind: directory
    Schedule: normal
    Last Changed Author: coderanger
    Last Changed Rev: 3397
    Last Changed Date: 2008-03-19 00:49:02 -0400 (Wed, 19 Mar 2008)
    

    In this case, there are two revision numbers: 4190 and 3397. 4190 is the last revision number for the repository, and 3397 is the revision number of the last change to the subtree that this workspace was checked out from. You can specify a path to a workspace, or a URL to a repository.

    A C# fragment to extract this under Windows would look something like this:

    Process process = new Process();
    process.StartInfo.FileName = @"svn.exe";
    process.StartInfo.Arguments = String.Format(@"info {0}", path);
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.Start();
    
    // Parse the svn info output for something like "Last Changed Rev: 1234"
    using (StreamReader output = process.StandardOutput)
    {
        Regex LCR = new Regex(@"Last Changed Rev: (\d+)");
    
        string line;
        while ((line = output.ReadLine()) != null)
        {
            Match match = LCR.Match(line);
            if (match.Success)
            {
                revision = match.Groups[1].Value;
            }
        }
    }
    

    (In my case, we use the Subversion revision as part of the version number for assemblies.)

提交回复
热议问题