31

如何使用 SharpSVN 获取最新版本号?

4

6 回答 6

40

从存储库中检索头部修订的最便宜的方法是 Info 命令。

using(SvnClient client = new SvnClient())
{
   SvnInfoEventArgs info;
   Uri repos = new Uri("http://my.server/svn/repos");

   client.GetInfo(repos, out info);

   Console.WriteLine(string.Format("The last revision of {0} is {1}", repos, info.Revision));
}
于 2009-03-26T09:08:15.523 回答
18

我正在使用 SvnWorkingCopyClient 检查最新版本的工作副本:

var workingCopyClient = new SvnWorkingCopyClient();

SvnWorkingCopyVersion version;

workingCopyClient.GetVersion(workingFolder, out version);

然后可以通过以下方式获得最新版本的本地工作存储库

long localRev = version.End;

对于远程存储库,使用

 var client = new SvnClient();

 SvnInfoEventArgs info;

 client.GetInfo(targetUri, out info);

 long remoteRev = info.Revision;

反而。

这类似于从命令行使用 svnversion 工具。希望这可以帮助。

于 2010-08-31T13:04:48.500 回答
9

好的,我自己想出来的:

SvnInfoEventArgs statuses;
client.GetInfo("svn://repo.address", out statuses);
int LastRevision = statuses.LastChangeRevision;
于 2009-03-26T09:04:15.143 回答
1

我也用谷歌搜索了很多,但唯一能让我真正获得最新版本的一件事是:

public static long GetRevision(String target)
    {
        SvnClient client = new SvnClient();

        //SvnInfoEventArgs info;
        //client.GetInfo(SvnTarget.FromString(target), out info); //Specify the repository root as Uri
        //return info.Revision
        //return info.LastChangeRevision

        Collection<SvnLogEventArgs> info = new Collection<SvnLogEventArgs>();
        client.GetLog(target, out info);
        return info[0].Revision;
    }

其他解决方案被注释掉。自己试一试,看看有什么不同。. .

于 2010-07-27T09:24:13.960 回答
0

好吧,一个快速的谷歌搜索给了我,它有效(只需指向 /trunk/ URI):

http://sharpsvn.open.collab.net/ds/viewMessage.do?dsForumId=728&dsMessageId=89318

于 2009-03-26T09:00:57.630 回答
0

这是一个非常古老的问题,在前两个答案中已经得到了很好的回答。尽管如此,希望它可能对我发布以下 C# 方法的人有所帮助,以说明如何不仅从存储库和工作副本中获取修订号,而且如何测试可能的典型情况被视为问题,例如在自动构建过程中。

  /// <summary>
  /// Method to get the Subversion revision number for the top folder of the build collection, 
  /// assuming these files were checked-out from Merlinia's Subversion repository. This also 
  /// checks that the working copy is up-to-date. (This does require that a connection to the 
  /// Subversion repository is possible, and that it is running.)
  /// 
  /// One minor problem is that SharpSvn is available in 32-bit or 64-bit DLLs, so the program 
  /// needs to target one or the other platform, not "Any CPU".
  /// 
  /// On error an exception is thrown; caller must be prepared to catch it.
  /// </summary>
  /// <returns>Subversion repository revision number</returns>
  private int GetSvnRevisionNumber()
  {
     try
     {
        // Get the latest revision number from the Subversion repository
        SvnInfoEventArgs svnInfoEventArgs;
        using (SvnClient svnClient = new SvnClient())
        {
           svnClient.GetInfo(new Uri("svn://99.99.99.99/Merlinia/Trunk"), out svnInfoEventArgs);
        }

        // Get the current revision numbers from the working copy that is the "build collection"
        SvnWorkingCopyVersion svnWorkingCopyVersion;
        using (SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient())
        {
           svnWorkingCopyClient.GetVersion(_collectionFolder, out svnWorkingCopyVersion);
        }

        // Check the build collection has not been modified since last commit or update
        if (svnWorkingCopyVersion.Modified)
        {
           throw new MerliniaException(0x3af34e1u, 
                  "Build collection has been modified since last repository commit or update.");
        }

        // Check the build collection is up-to-date relative to the repository
        if (svnInfoEventArgs.Revision != svnWorkingCopyVersion.Start)
        {
           throw new MerliniaException(0x3af502eu, 
             "Build collection not up-to-date, its revisions = {0}-{1}, repository = {2}.",
             svnWorkingCopyVersion.Start, svnWorkingCopyVersion.End, svnInfoEventArgs.Revision);
        }

        return (int)svnInfoEventArgs.Revision;
     }
     catch (Exception e)
     {
        _fLog.Error(0x3af242au, e);
        throw;
     }
  }

(这段代码确实包含了一些特定于它被复制的程序的东西,但这不应该使 SharpSvn 部分难以理解。)

于 2014-07-27T23:11:13.983 回答