开发者

hooking into SVN in a asp.net web application

开发者 https://www.devze.com 2022-12-11 12:37 出处:网络
How hard is it to create a repository via c#? What about开发者_如何学C viewing a source code file, or a diff, in a web app?

How hard is it to create a repository via c#? What about开发者_如何学C viewing a source code file, or a diff, in a web app?

Is there an api I need to hook into or is it all custom code I have to write?


SharpSVN provides you with a full API. It's not that easy to use and is generally quite slow unless you cache the items you get back.

SharpSvn is a binding of the Subversion Client API for .Net 2.0 applications contained within a set of xcopy-deployable dll's. Notable users of this api are (at this time):

  • AnkhSVN 2.X - Subversion Support for Visual Studio 2005 and 2008
  • CollabNet Desktop for Visual Studio
  • SharpDevelop (#develop)
  • MonoDevelop
  • SVN-Monitor
  • And many, many other projects..

Here's an example from an ASP.NET project I got about 50% through, that displayed all items from a repository:

using (SvnClient client = new SvnClient())
{
    client.LoadConfiguration(Server.MapPath("/"));
    SvnUriTarget target = new SvnUriTarget("http://wush.net/svn/yourusername/", SvnRevision.Head);
    SvnListArgs args = new SvnListArgs();

    Collection<SvnListEventArgs> svnList = new Collection<SvnListEventArgs>();
    client.Authentication.DefaultCredentials = new NetworkCredential("username", "password);
    args.Depth = SvnDepth.Children;
    client.GetList(target, args, out svnList);

    foreach (var item in svnList)
    {
        // display the list  
    }

}


Well, the SVN project doesn't provide any direct support for C# (or the .NET framework for that matter) - since .NET is not truly cross-platform. There are C bindings and I've recently come across an open source C# bindings project. You may want to take a look at Subersion Sharp. It seems it has support for most of what you're interested in.

Here's a quote from the site:

SubversionSharp is a C# wrapper that fully covers the client API of Subversion SCM. Easy access to the Subversion API is provided without any compromise on fonctionality. This library is the starting point to easily integrate Subversion repositories in any .NET managed software. These C# bindings for Subversion has been written for portability and performances. This library is now available for both Mono/Linux and .NET/Windows environments.

And actually, most likely you'll be interested in the SVN.NET branch since it supports .NET 2.0 while SubervsionSharp doesn't. Of course, if you're developing with a more recent version of .NET 3.0/3.5 you should be able to get the source code and compile it to target the newer versions.

I was looking into it the other day for similar purposes but since got a bit detoured because of other high priority work..


There are a couple of C# interfaces to the subversion client API SubversionSharp and SVN.net. However the creation of repos is covered by the server api. You might just exec out for that part and then handle the rest through the API


SharpSVN looks like one of the most active API, the two others - SubversionSharp and SVN.NET - haven't changed in months (I think they've "merged" at some point, the former is definitely out).

It also has the advantage of coming from CollabNet, which makes it the most "official", and probably reliable.

If you want support for multiple platforms, using Mono, you will have to check though, one year ago it was not totally portable, especially regarding the authentication callbacks.


I have written .net application that uses svn extensively and can say that you don't need the bindings at all.

They are harder to use and are not up to date - new svn versions come out almost every couple of months and it is hard to catch up. It is also harder to redistribute new versions of the bindings when they eventually come out.

Most of the time it would be sufficient to call svn.exe and svnadmin.exe. Both are non-interactive tools and as long as you supply all parameters that you need you will be fine.

If you don't have to execute A LOT of svn operations go for the command line tools - call them from your .NET application/website.

Another advantage is that you don't have to handle x86/x64 issues - if you use the bindings you have to make sure you the combination of the svn dll, your program and OS match.


DotNetSvn is another project that is attempting to create a wrapper for Subversion in .net. If you want to see how other projects have created their own wrappers, you can take a look at the source code of TortoiseSVN and maybe get some ideas of it.

Good luck with your project and hope this helped some.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号