tags:

views:

139

answers:

6

How hard is it to create a repository via c#? What about 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?

+1  A: 

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..

Miky Dinescu
+1  A: 

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

stimms
+1  A: 

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.

RedGlyph
A: 

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.

Chris
Hum, are you sure this project is still alive?
RedGlyph
Ouch, thought that was the project's home page. I changed the link to the code.google.com home page instead.
Chris
I'm afraid it seems as dead as the other link, sorry. And AFAIK, TortoiseSVN is in C++, not C#.
RedGlyph
Yeap. I know that Tortoise isn't in C#, but because it is GPL'd open source, I thought that by taking a look at how someone else accessed Subversions API might be of use.
Chris
+3  A: 

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  
    }

}
Chris S
Just out of curiosity, have you tested it recently on different platforms (.NET/Mono with Windows, Mono on Linux, ...), especially with client authentication?
RedGlyph
Agreed; I've used this very successfully on a recent project. The others mentioned may work too - but I stopped looking at alternatives as soon as this one worked fine.
Marc Gravell
@RedGlyph I haven't tried in the last 6 months, and the application I produced was only tested on Windows. My plan was to make a web app for editing files in, for doing minor changes to google code. It may be faster now, it wasn't using webdav iirc
Chris S
Looking at their list again - it says MonoDevelop so I assume it does work cross platform or atleast on Linux
Chris S
@Marc: My feeling exactly, I also had some success with it (except a few issues with Mono as I mentioned in my post), and other API's seem to have given up. @Chris: Yes, I saw that recently but I didn't get around to testing it with SVN. One can reasonably hope it'll be ported, if not now at least in the near future :-) - Anyway that was just for my personal curiosity, the OP didn't specify it _had_ to be portable. So thanks for the fb!
RedGlyph
+1  A: 

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.

devdimi
The problem when calling them for client operations is authentication, hopefully the OP won't need that from what they said. I didn't find any way with the pipes to check if authentication was needed because SVN does that in a very tricky way, let alone send the password in a reliable way. That being said, for admin operations that would probably be the most portable and lasting solution - even if not as elegant as an API ;-)
RedGlyph
There are arguments for the username/password. They have to be supplied every time in non-interactive scenario and it just works.
devdimi