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

有帮助吗?

解决方案

在最便宜的方式来从储存库检索头修订 是信息命令。

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));
}

其他提示

我使用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,如果工具。希望这有助于。

好的,我自己想通:

SvnInfoEventArgs statuses;
client.GetInfo("svn://repo.address", out statuses);
int LastRevision = statuses.LastChangeRevision;

我也用Google搜索了很多,但只有一两件事,这是为我工作得到真正的最新的版本是:

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;
    }

其他的解决方案是注释。自己尝试,看到了差距。 。

好了,一个快速谷歌搜索给我的,和它的作品(只是点在/树干/ URI):

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

这是一个非常古老的问题,并已在上面两个答案已经回答得很好。不过,在希望它可能有一定的帮助的人我张贴下面的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份难以理解。)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top