当我通过SharpSvn以编程方式添加文件时,另一个进程正在使用该文件

时间:2018-03-27 08:44:00

标签: c# svn sharpsvn

我们正在使用SharpSvn以编程方式向SVN龟添加SolidWorks文件。 在SolidWorks中打开文件时,我想通过代码将其添加到SVN而不关闭文件。 我使用下面的代码

        var SvnResult = new SvnResult();
        var FullPath = SvnHelper.FileCombine(FileName);

        try
        {

            var SvnArg = new SvnAddArgs();
            SvnArg.Force = true;
            SvnArg.Depth = SvnDepth.Infinity;
            //
            SvnClient.Add(FullPath, SvnArg);

            SvnResult.Message = "Success.";
            SvnResult.Status = true;
            //
            return SvnResult;
        }
        catch (SvnException exc)
        {
            SvnResult.Message = exc.Message;
            SvnResult.Status = false;
            return SvnResult;
        }

我得到这样的错误: 该进程无法访问该文件,因为它正由另一个进程使用。

如何在不关闭文件的情况下将其添加到SVN? 的问候,

1 个答案:

答案 0 :(得分:0)

我们解决了这个问题。起初我们使用TortoiseSvn.exe命令行来添加和提交文件,但是当我们用来发送commit命令时,引发了svn Dialog表单。为解决此问题,我从svn安装程序安装“命令行客户端工具”。通过安装此选项,您可以在svn路径“C:\ Program Files \ TortoiseSVN \ bin”下找到svn.exe。 我将此路径添加到Environment Variables,然后在文件打开时使用svn命令行添加和提交。

public SvnResult CommitFiles_BySVNCmd(string filePath)
    {
        var fullPath = SvnHelper.FileCombine(filePath);
        var svnResult = new SvnResult();

        try
        {
            // svn add command
            var status = GetStatus(fullPath);
            //
            if (status.LocalContentStatus == SvnStatus.NotVersioned)
            {

                var argumentsAdd = $@"add {fullPath}";
                ProcessStart(argumentsAdd);
            }


            // svn commit command
            var argumentsCommit = $@"commit -m Commited_Automatically {fullPath}";
            ProcessStart(argumentsCommit);


            svnResult.Message = "Success
            svnResult.Status = true;

            return svnResult;

        }
        catch (SvnException se)
        {

            svnResult.Message = se.Message;
            svnResult.Status = false;

            return svnResult;
        }
    }

private void ProcessStart(string arguments)
{
     var processInfo = new ProcessStartInfo("svn", arguments);
     processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
     Process.Start(processInfo);
}

最诚挚的问候,

相关问题