简体   繁体   English

如何使用SVN和.NET以编程方式进行文件版本控制?

[英]How to programatically do file versioning with SVN and .NET?

We have a report generator. 我们有一个报告生成器。 Daily, it writes its data into a excel file. 每日,它将其数据写入excel文件。

For reasons of version controlling and file data safety, we need to alter this file, and commit the changes into a repository. 出于版本控制和文件数据安全的原因,我们需要更改此文件,并将更改提交到存储库。

Do you recommend any .net SVN API you've used? 您推荐使用过任何.net SVN API吗?

You should take a look at the SharpSvn .NET library. 您应该看一下SharpSvn .NET库。 You will probably need checkout and commit commands: 您可能需要checkout和commit命令:

Checking out: 退房:

string wcPath = "c:\\my working copy";
using (SvnClient client = new SvnClient())
{
    client.CheckOut(new Uri("http://server/path/to/repos"), wcPath);
}

Committing: 承诺:

string wcPath = "c:\\my working copy";
SvnCommitArgs a = new SvnCommitArgs();
a.LogMessage = "My log message";

using (SvnClient client = new SvnClient())
{
    client.Commit(wcPath, a);
}

We are using tool that actually searching for installed TortoiseSVN in predefined locations and using it command-line api. 我们正在使用实际在预定义位置搜索已安装的TortoiseSVN并使用命令行api的工具。 If that is for Windows and it's for not redistribution - it might be easier to do. 如果这是针对Windows而且不是为了重新分发 - 那么可能更容易。

Helpful code for cmd: 有用的代码为cmd:

@echo off
if exist "%ProgramW6432%\TortoiseSVN\bin\TortoiseProc.exe" set patht=%ProgramW6432%
if exist "%ProgramFiles%\TortoiseSVN\bin\TortoiseProc.exe" set patht=%ProgramFiles%
if exist "%ProgramFiles(x86)%\TortoiseSVN\bin\TortoiseProc.exe" set patht=%ProgramFiles(x86)%

echo Placing SVN Commit
"%patht%\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:"%CD%" /notempfile    

If you still want to do that task from code - SharpSVN http://sharpsvn.open.collab.net is better choiсe 如果您仍想从代码中执行该任务 - SharpSVN http://sharpsvn.open.collab.net更好的选择

You might be able to turn on Autoversioning for your repository. 您可以为您的存储库启用Autoversioning Since it uses WebDAV, you can treat the repository just like a network drive (Web Folder). 由于它使用WebDAV,您可以将存储库视为网络驱动器(Web文件夹)。 And you can treat the file as a normal file, just open, modify, and save. 您可以将文件视为普通文件,只需打开,修改和保存即可。

If it were me , I would create a new repository for the excel data files. 如果是我,我会为excel数据文件创建一个新的存储库。 I don't think I'd like my code being autoversioned :) 我不认为我希望我的代码被自动转换:)

The simplest would be to spawn a process and call SVN.exe to commit your changes. 最简单的方法是生成一个进程并调用SVN.exe来提交更改。

Here is a similiar question that was asked. 这是一个类似的问题。

Does anyone know of a good C# API for Subversion? 有没有人知道Subversion的C#API?

Here is another resource 这是另一种资源

SVN Libraries for .NET? 适用于.NET的SVN库?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM