【问题标题】:The file being use by another process when i add it programatically by SharpSvn当我通过 SharpSvn 以编程方式添加文件时,另一个进程正在使用该文件
【发布时间】:2020-10-21 00:20:14
【问题描述】:

我们正在使用 SharpSvn 以编程方式将 SolidWorks 文件添加到 SVN 乌龟。 在 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? 问候,

【问题讨论】:

    标签: c# svn sharpsvn


    【解决方案1】:

    我们解决了这个问题。起初我们使用 TortoiseSvn.exe 命令行来添加和提交文件,但是当我们使用发送提交命令时,出现了 svn 对话框形式。为了解决这个问题,我从 svn 安装程序中安装了“命令行客户端工具”。通过安装此选项,您可以在 svn 路径“C:\Program Files\TortoiseSVN\bin”下找到 svn.exe。 我将此路径添加到环境变量中,然后在文件打开时使用 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);
    }
    

    最好的问候,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      • 2021-06-08
      • 1970-01-01
      相关资源
      最近更新 更多