SharpSVN에서 최신 개정 번호를 얻는 방법은 무엇입니까?
문제
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;
나는 또한 많은 것을 구글링했지만 실제로 마지막 개정을 얻기 위해 노력했던 유일한 것은 다음과 같습니다.
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;
}
다른 솔루션은 언급됩니다. 혼자서 시도하고 차이점을보십시오. . .
글쎄, 빠른 Google 검색이 저에게 그것을 주었고, 그것은 작동합니다 ( / trunk / 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 부분을 이해하기 어렵게 만들지 않아야합니다.)