使用SharpSvn方便调用svn

需要调用svn去做一些操作时,有两种方式:调用svn.exe命令行和调用svn api接口。我不太喜欢调用命令行的方式,是因为它需要依赖一个外部的exe程序,同时,为了得到命令执行结果,还需要去捕捉命令行的输出控制台,然后去解析,使得不太可靠。因此,我选择了调用svn接口的方式,因为我使用的是c#,有一个现成的第三方包装的库SharpSvn可以调用。

SharpSvn主页:

http://sharpsvn.open.collab.net/

使用起来很简单,下面是一个例子:

static void Main(string[] args)
{
    
using (SvnClient client = new SvnClient())
    {
        SvnInfoEventArgs serverInfo;
        SvnInfoEventArgs clientInfo;
        SvnUriTarget repos 
= new SvnUriTarget("http://svn.test.com/demo");
        SvnPathTarget local 
= new SvnPathTarget(@"d:\Work\Code\demo");

        client.GetInfo(repos, 
out serverInfo);
        client.GetInfo(local, 
out clientInfo);

        
string path = @"d:\Work\Code\Demo";
        client.CleanUp(path);
        client.Revert(path);
        client.Update(path);

        Console.WriteLine(
string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision));
        Console.WriteLine(
string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision));
    }
}
微信扫一扫交流

作者:CoderZh
公众号:hacker-thinking (一个程序员的思考)
独立博客:http://blog.coderzh.com
博客园博客将不再更新,请关注我的「微信公众号」或「独立博客」。
作为一个程序员,思考程序的每一行代码,思考生活的每一个细节,思考人生的每一种可能。
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/coderzh/p/sharpsvn.html