自动获取svn的版本号

需求

在做打包时,需要获取本地svn仓库的版本号,如下所示:

image

下面是我试过的几种做法

SubWCRev

使用SubWCRev.exe(TortoiseSVN自带的小工具),用法简单,但获取到的版本号有时候会有一定的出入,比如svn的日志在58之后下个版本就是60时,就会有出入。其它情况下是正常的。

用法:通过指定的template,进行替换

svninfo.template的内容如下:$WCREV$

svninfo.txt

用法:SubWCRev.exe xxx路径 xxx路径/svninfo.template xxx路径/svninfo.txt

运行之后就会根据svninfo.template中的模板自动往svninfo.txt中替换成相应的内容

参考:http://blog.csdn.net/analogous_love/article/details/47293509

 

SVN 命令

使用svn 自带的命令,可以打印出来,但是不会在bat中处理这些字符串,还是放弃了

如下:

image

svn info 查看当前的信息

svn log –l 1 查看最后的一个提交信息

找到一个可用的bat语句如下:https://github.com/zhaoqingqing/blog_samplecode/blob/master/workflow-tools/BAT/bat%E8%8E%B7%E5%8F%96svn%E7%89%88%E6%9C%AC%E5%8F%B7.bat

for /f "tokens=5" %%i in ('SubWCRev  e:\3dsn\client\client_demo_ios\^|find "Last committed at revision"') do set version=%%i

echo %version%

pause

 

sharpsvn

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

不得不吐槽下,这个文档真的是很少!

下面是我写的获取本地及服务器版本号

private static string ServerUrl = "http://svn2.666.com/client/client_demo/";
private static string localPath = @"e:/xxx/client/client_demo_ios/";

static void Main(string[] args)
{
    //获取服务器最新的版本号
    Uri url = new Uri(ServerUrl);
    SvnRemoteSession svnRemoteSession = new SvnRemoteSession(url);
    long lastReversion = 0;
    svnRemoteSession.GetLatestRevision(out lastReversion);
    Console.WriteLine("服务器版本号:{0}",lastReversion);

    //获取本地版本号
    using (SvnClient client = new SvnClient())
    {
        SvnPathTarget svnPathTarget = new SvnPathTarget(localPath);
        SvnInfoEventArgs info;
        client.GetInfo(svnPathTarget, out info);
        Console.WriteLine("本地版本:{0}", info.Revision);
    }
    
}
posted @ 2017-03-22 20:27  赵青青  阅读(3190)  评论(0编辑  收藏  举报