Download SVN Code Automatically Using C#


During the development phase, developers check out and check in source code every day. Sometimes, the source code checkout task to a local repository could be automatically executed by a job. Automation of these activities will help to automate code setup in the developer’s machine or the build process of an application. In this article, I will demonstrate an automated SVN checkout process from a C# console application. The Tortoise SVN command line tool uses svn.exe. This tool is helpful to pull code from an SVN server.

What Is Tortoise SVN?

Tortoise SVN is a free, easy to use, open source Windows shell extension for the Apache Subversion version control system. Subversion provides a command line and GUI client to run. Source code is maintained in the Tortoise SVN central repository that manages files and directories. Developers use the SVN client to check out and check in source code. To automate SVN checkout, we need to have Tortoise SVN installed, along with command line client tools.

SVN Command line tools will install svn.exe, that will be used in our Visual Studio code for checkout.

Sample Code for SVN Automation

Step 1

Create a console application in Visual Studio and name it SVNCheckOut. Add the following App.config file in the application and create the required app setting keys.

  • SVNURL – Server URL: Code repository and version control server
  • SVNUserName: User name of the SVN
  • SVNPassword: Password of the SVN repository
  • SVNLocalCodePath: Local developer’s machine path to check out code
  • TortoiseSVNPath: Path where SVN is installed locally
<?xml version="1.0" encoding="utf-8" ?>
      <add key="SVNURL" value="sampleURL" />
      <add key="SVNUserName" value="XYX" />
      <add key="SVNPassword" value="XYZ" />
      <add key="SVNLocalCodePath" value="C:TapasLocalSVN" />
      <add key="TortoiseSVNPath" value="C:Program Files
         TortoiseSVNbin" />

Step 2

In the main method, I have written the following code to pull the SVN URL, local path, user name, and password from the app settings. To download the code from SVN, I have called the CheckOutSVNCode method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SVNCheckOut
   public class SVNSample
      public void Main(string[] args)
         string strSVNURL = System.Configuration.Configuration
         string strSVNUserName = System.Configuration.Configuration
         string strSVNPassword = System.Configuration.Configuration
         string strSVNLocalCodePath = System.Configuration
         string strTortoiseSVNPath = System.Configuration
         CheckOutSVNCode(strSVNURL, strSVNUserName, strSVNPassword,
            strSVNLocalCodePath, strTortoiseSVNPath);


      private static void CheckOutSVNCode(string strSVNURL,
         string strSVNUserName, string strSVNPassword,
         string strSVNLocalCodePath, string strTortoiseSVNPath)
         string arguments = " checkout " + strSVNURL + " " +
            strSVNLocalCodePath + "  --username " + strSVNUserName
            + " --password " + strSVNPassword;
         ProcessStartInfo info = new ProcessStartInfo("svn.exe",
         info.WorkingDirectory = strTortoiseSVNPath;
         info.WindowStyle = ProcessWindowStyle.Normal;
         Console.WriteLine("Checkout started");

Step 3

In the CheckOutSVNCode method body, I have executed run svn.exe with the arguments necessary to pull code from SVN and save it in the local code repository.

Checkout SVN supports a big list of commands. Developers can automate the process to extend these commands from an application by passing various commands to svn.exe and automate the code setup or build process. Following is the list of frequently used commands SVN.exe supports.


svn update [-r rev] PATH

For updating items in Subversion.

Update to Revision

svn update [-r rev] [-depth ARG] [--ignore-externals] PATH


svn commit -m "LogMessage" [-depth ARG] [--no-unlock] PATH...

LogMessage here represents the contents of the log message edit box.


svn diff PATH

TortoiseSVN just feeds the two files into the chosen diff program and shows the differences.

Show Log

svn log -v -r 0:N --limit 100 [--stop-on-copy] PATH


svn log -v -r M:N [--stop-on-copy] PATH

Revision Graph

svn info URL_of_WC
svn log -v URL

Repo Browser

svn list [-r rev] -v URL

You can use svn info to determine the repository root. Also, this command returns all the locking information shown in the repository browser.


svn resolved PATH




svn delete PATH


svn revert [-R] PATH...


I hope this article explains how to automate the SVN checkout process. Because all commands for Tortoise SVN are controlled through command line parameters, a developer can automate it with batch scripts or applications. That’s all for today. Happy coding!


More by Author

Must Read