The. NET interface sharpsvn of the svn client API refers to the instance for checking checkout operations.

Source: Internet
Author: User

Subversion is a file version management tool, which is widely used as the source generation version management.

Existing tools, whether it's their own command line tool or Windows UI's tortoisesvn, are also very easy to use. However, if you want to integrate with existing systems, in addition to the built-in hook Script Function, SVN APIs must be used. This API uses C-producer, so for other developers, Java APIs are used, C # is inconvenient to use.

As a result, the svn client's Java can be implemented, or the DLL package of the C interface is replaced by a complete token (swig) in other languages ), in this way, we can easily use other statements to communicate with SVN repository.

Sharpsvn is. NET platform's svn api has been widely used in tools such as ankhsvn, and can be used to develop a custom client for SVN, or use it to integrate with other systems such as bug/Cr tracking.

 

The following is a simple guide compiled by a Web user, similar to hello World, telling us how to start using sharp SVN

The sharpsvn library basically gives you a. net interface to all the operations that you wowould normally perform through a tool like tortoisesvn.

I found myself needing this exact library while writing a tool that changes files that have been checked out from SVN.

The problem with manipulating files that are under SVN is that you need to be careful about renaming files (and sometimes even deleting ). if you don't do it through the svn API then you will end up with duplicates files/folders in SVN since SVN thinks that it's a new file.

To solve this I finally got a chance to crack open the sharpsvn library which is used by my favorite ankhsvn.

1. download the latest library from http://sharpsvn.open.collab.net /. you have to pick between either 1.5 or 1.6. I went with 1.6 and didn't run into any issues. I think this is based on the version of the svn server that your connecting.

2. In your Visual Studio project Add a reference to the following assemblies.
-Sharpsvn. dll
-Sharpsvn. UI. dll (only needed if you need the UI to prompt for login)

3. if like me your building on a 64 bit OS and you want your app to run on a 32 bit OS, make sure the project that references the sharpsvn. DLL is set to build for the X86 platform. (build-> Configuration Manager-solution platform)

4. Write your code using the svnclient object. Here are some samples from the sharpsvn Wiki and some that I wrote.

Showlog operations

Using (svnclient client = new svnclient ())

{
// Client. Authentication. Clear ();
Client. Authentication. usernamepasswordhandlers + = new eventhandler <sharpsvn. Security. svnusernamepasswordeventargs> (
Delegate (Object S, sharpsvn. Security. svnusernamepasswordeventargs ee)
{
Ee. Username = "your zookeeper ";
& Nbsp; & nbsp; EE. password = "your password ";
});

Client. Authentication. sslservertrusthandlers + = new eventhandler <sharpsvn. Security. svnsslservertrusteventargs> (
Delegate (Object ssender, sharpsvn. Security. svnsslservertrusteventargs SE)
{
// Look at the rest of the arguments of E whether you wish to accept

// If accept:
Se. acceptedfailures = Se. failures;
Se. Save = true; // save acceptance to authentication store
});

This.txt log. Text + = datetime. Now. tolongtimestring () + "\ r \ n ";
Svnlogargs logargs = new svnlogargs ();
Logargs. range = new svnrevisionrange(long.parse(this.txt revisionfrom. Text), long.parse(this.txt revisionto. Text ));
Logargs. retrieveallproperties = true;

Eventhandler <svnlogeventargs> loghandler = new eventhandler <svnlogeventargs> (delegate (Object Lo, svnlogeventargs le)
{
Foreach (svnchangeitem changeitem in Le. changedpaths)
{
This.txt log. Text + = string. Format (
"{0} {1} {2} {3} {4} \ r {5} {6 }",
Changeitem. Action,
Changeitem. path,
Changeitem. copyfromrevision,
Changeitem. copyfrompath,
Le. Author,
Le. logmessage,
Le. Revision );

}
});

Client. Log (New uri (<a href = "https: // URL"> https: // URL </a>), logargs, loghandler );
This.txt log. Text + = datetime. Now. tolongtimestring () + "\ r \ n ";
}

 

Using (svnclient client = new svnclient ())

{
// Client. Authentication. Clear ();
Client. Authentication. usernamepasswordhandlers + = new eventhandler <sharpsvn. Security. svnusernamepasswordeventargs> (
Delegate (Object S, sharpsvn. Security. svnusernamepasswordeventargs ee)
{
Ee. Username = "your zookeeper ";
Ee. Password = "your password ";
});

Client. Authentication. sslservertrusthandlers + = new eventhandler <sharpsvn. Security. svnsslservertrusteventargs> (
Delegate (Object ssender, sharpsvn. Security. svnsslservertrusteventargs SE)
{
// Look at the rest of the arguments of E whether you wish to accept

// If accept:
Se. acceptedfailures = Se. failures;
Se. Save = true; // save acceptance to authentication store
});

Client. Checkout (
New uri ("https: // yoursvn-server: 8443/SVN/PRD/utl/trunk/excelpool"), // SVN repository URL
@ "C: \ WC"); // local direcotory

}

Add new files to the working copy

Using (svnclient client = new svnclient ())
{
Svnaddargs ARGs = new svnaddargs ();
// Todo: Set optional settings on ARGs

Client. Add (@ "C: \ file \ In \ workingcopy", argS );

 

 

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.