Does it work?

Guide to Versioning a Visual Studio Solution with Subversion, TortoiseSVN and AnkhSVN

1. Introduction
2. Resources
3. Prerequisites – Install Software
4. Setup a Subversion Repository with the Help of TortoiseSVN
4.1. Create a Repository
4.2. Set a Security Policy
4.3. Run Subversion Server Process
5. Checkout a Working Copy
6. Add content and Commit
6.1. Add a Text File to Versioning
6.2. Add a Visual Studio Solution to Versioning (TortoiseSVN)
6.3. Add a Visual Studio Solution to Versioning (AnkhSVN)
7. Install Subversion as a Service

1. Introduction

In this article I will describe the process of setting up a working Subversion server, creating a repository and add to versioning a Visual Studio solution to work with.

2. Resources

During this article I will guide you through the installation process of the following software:


→ top of post
→ top of paragraph

3. Prerequisites – Install Software

Install TortoiseSVN

Download the latest TortoiseSVN release from the download page and launch the installer. In the custom setup screen modify the default selections by adding: ‘command line client tools’.

Subversion server and command line client tools will be installed, together with TortoiseSVN, under: %ProgramFiles%\TortoiseSVN\bin.

The path will be added to the %path% Environment Variable so that all commands will be available from any working directory.

Now open a command prompt and digit svn help. You should be able to see svn syntax information.
The installation succeeded.

→ top of post
→ top of paragraph

Install AnkhSVN

Open Visual Studio, go to: Tools –> Extensions and Updates and type: AnkhSVN in the search box.

Click Download and once download completed, close Visual Studio.

A VSIX installer window will open for AnkhSVN. Click on the ‘Modify’ button.

AnkhSVN Extension will be installed for Visual Studio 2017.

Upon reopening Visual Studio go to: Tools –> Options –> Source Control –> Plug-in Selection

and choose AnkhSVN.

Now that you have installed it, forget it for a while and step through the next paragraphs.

→ top of post
→ top of paragraph

4. Setup a Subversion Repository with the Help of TortoiseSVN

Now you have a very cool GUI for Subversion provided by TortoiseSVN.
In the following paragraphs we will setup a Subversion repository on the local machine and we will start working with it.

4.1. Create a Repository

Create a new directory, e.g.: C:\develop\test\repo, right click it and choose: TortoiseSVN –> Create repository here… (see: Figure 1).

The new repository will be created and an informational message will tell you that ‘The Repository was successfully created‘ (see: Figure 2).
In the same prompt you will be asked to create the default folder structure, if needed. Click on the button: ‘Create folder structure’ to do it.
You will be prompted with a modal stating: ‘Default directory structure successfully created!’

Close all the prompts and this step is done.

Create repo here

Figure 1. Context menu for the ‘repo’ directory

Figure 2. Default folder structure prompt for the repository

4.2. Setup a Security Policy

Before starting to use your freshly created repository you must set a security policy, that is, you must create user accounts for the repository.
First of all open the file: C:\develop\test\repo\conf\svnserve.conf.
Have a read to the file and notice that all lines are commented (the pound character: # is the comment character).
Uncomment rows 19 and 20, remove any leading spaces at the beginning of the rows and change them to fit your security policy.
You can, for instance, decide to deny access to the repository to anonymous users and to unauthorized ones while giving full access to authorized users.
To obtain this result set those two lines as follows:

anon-access = none
auth-access = write

Then uncomment row 27 to tell Subversion where the user accounts information will be stored:

password-db = passwd

where ‘passwd‘ is the name of a file in the same directory as ‘svnserve.conf‘ (C:\develop\test\repo\conf\passwd).
Open the ‘passwd‘ file and you will find two example rows, at rows 7 and 8, showing the syntax to define users:

# harry = harryssecret
# sally = sallyssecret

The two lines are commented but they clearly show that the syntax is:

user = password

Add information about the account that you will use to access the repository (e.g.: test = test).

4.3. Run Subversion Server Process

You can simply start svn server process from the command line.
Open a command prompt and digit:

svnserve -d -r “C:\develop\test\repo”

and you’re done!
If you prefer to run Subversion in order to let it manage different repositories placed under a common directory, you can run the Subversion server process in that directory, e.g.:

svnserve -d -r “C:\develop”.

The row above will let Subversion be able to expose repositories placed in the paths:


If you prefer to run Subversion as a Windows service, have a look at the paragraph: Install Subversion as a Service.

5. Checkout a Working Copy

Now let’s add some content.

You can prepare your workin copy or, in Subversion language, checkout your working copy.
Create a new directory named ‘wc’: C:\develop\test\wc.
Right-click the directory: C:\develop\test\repo and choose: SVN Checkout…. The Checkout panel will open.
Notice that the box: ‘URL of repository‘ is already filled with the path: file:///C:/develop/test/repo (see: Figure 3).

Figure 3. Checkout window.

You need to modify that path to match the exact path to the repository and you can do it in one of two ways:

  • Just add ‘trunk‘ to the path, because we want that only the content under that directory is copied in our working copy.
    The ‘URL of repository‘ will then be: file:///C:/develop/test/repo/trunk.
    This choice doesn’t need to have svnserve running and it’s good for a local test environment.
  • If you want to use Subversion through your network (i.e. in a real environment) and if you want to take advantage of the Subversion security policy that we have set up in the previous paragraph, you’d better use this alternative option:
    Let’s assume that you have run svnserve with the following row: svnserve -d -r “C:\develop\test\repo” as explained in paragraph 4.3.
    Delete the content of the ‘URL of repository‘ box and replace it with: ‘svn://localhost/trunk‘.
    The example is provided assuming Subversion server installed on the local machine but you can replace localhost with the server machine name or IP address.
    We need to specify the path of the repository relative to the working directory of Subversion (svnserve), which is: C:\develop\test\repo, so the path that we specify is simply: trunk.

In the rest of the article we will assume the second choice.
After having set the ‘URL of repository‘ we must fill the ‘Checkout directory‘ box and we can do it browsing to C:\develop\test\wc by means of the adjacent button (see: Figure 4).
Make sure that ‘HEAD revision‘ is checked and click OK.

Figure 4. Checkout window filled.

If you have set the ‘URL of repository‘ to svn://localhost/trunk you will be prompted for username and password (see Figure 5).

Figure 5. Prompt for username and password.

Fill both fields with: ‘test‘ or whatever account information you configured in the paragraph: 4.2. Set a Security Policy and flag the ‘Save authentication‘ checkbox, then click OK.
An informational window will appear stating that the checkout was succesfully created (see: Figure 6).

Figure 6. Checkout completed.

Close that window and look inside the C:\develop\test\wc directory.
The wc directory has been filled with the content from the repository’s trunk directory, that is the directory is empty.
Actually it’s not quite empty: there’s a directory named .svn inside it.
Such directory contains all the information needed by Subversion to keep track of the history of all the files that will be added to versioning inside this directory.
Now let’s go to the following step and start adding content.

6. Add content and Commit

6.1. Add a Text File to Versioning

Let’s add a simple text file to versioning: create a file named ‘test.txt‘ inside C:\develop\test\wc.
Right-click it and choose: TortoiseSVN –> Add… (see: Figure 7), then click OK at the following two prompts and you will see an overlay blue plus icon above your file meaning that the file has been scheduled for inclusion in the repository upon the next commit.

Figure 7. Add file to Versioning.

If you can’t see the overlay icon, just press F5 to refresh the screen.
Now execute your first commit thus sending the new file to the repository. From now on, its changes will be tracked by the Subversion versioning system.
If you want to commit the content of the directory all at once (only one file at the moment) just go up one level, right click on the directory: C:\develop\test\wc and choose: SVN –> Commit… (see: Figure 8).
If you checked the ‘Save authentication‘ checkbox when checking out the working copy (as shown in 5. Checkout a Working Copy) you won’t be prompted, now, for username and password.

Figure 8. Commit working copy content with TortoiseSVN.

The Log Message window will open (see: Figure 9), waiting for you to provide a meaningful message. Write: “Added empty test file” and click OK.

Figure 9. Provide a meaningful message before committing.

Make sure that everything worked fine when the informational window titled: ‘Commit Finished!‘ will appear.
If everything is alright then click OK.

Now you can start adding content to the file and commit the changes to the repository.

→ top of post
→ top of paragraph

6.2. Add a Visual Studio Solution to Versioning (TortoiseSVN)

Let’s talk about versioning a Visual Studio solution (I won’t talk here about how to create Visual Studio solutions and projects).
Open Visual Studio (I’m working with Visual Studio 2017) and create a new blank solution inside C:\develop\test\wc.
Name the solution: DummySolution.sln and add one project to the solution: DummyProject.csproj.

Now you can add the solution to versioning in one of two ways:

  1. adding the solution file and the projects directories with TortoiseSVN;
  2. installing AnkhSVN and versioning the solution directly from Visual Studio;

In this paragraph we’ll see the first option while in the next paragraph we will repeat the same actions with AnkhSVN.

Select the solution file: DummySolution.sln and the project directory: DummyProject.
Be careful not to select the file: DummySolution.suo, which contains solution-wide configuration data specific to every developer’s machine.

Then right-click one of the selected items and choose: TortoiseSVN –> Add…..
In the Add window (see: Figure 10) uncheck the directories: bin and obj of each project and the files: DummyProject.csproj.user and DummyProject.Tests.csproj.user if you find any of them in the list of checked items.
Click OK and a report window, titled: Add… Finished!, should appear if everything worked well. Click OK again as you did for the ‘test.txt’ file.
Now all the content needed is scheduled to be added to versioning upon the next commit action.

Figure 10. Add window.

Now you can commit the freshly added content to the repository: right click on the directory C:\develop\test\wc and choose: SVN –> Commit… as you did when you added the test.txt file.

6.3. Add a Visual Studio Solution to Versioning (AnkhSVN)

As an alternative to previous paragraph, we can add the Visual Studio solution to versioning directly from the Visual Studio GUI with the help of AnkhSVN.

Before reading the current paragraph you need to install AnkhSVN as in Install AnkhSVN.

Open the solution file: DummySolution.sln with Visual Studio 2017.

AnkhSVN will recognize that the solution is inside a Subversion working copy and will show the files with a ‘+’ icon.

Figure 11. AnkhSVN: solution marked to be added.

Right-clicking solution file we can choose the option to explicitly mark the solution file to be added to the repository:

Figure 12. AnkhSVN: add solution file to repository.

You can now commit the solution to the repository by right-clicking the solution entry in Solution Explorer:

Figure 13. AnkhSVN: commit solution changes

You will not be prompted for username and password if you already saved them while using TortoiseSVN.

A window will popup showing you the files that AnkhSVN is going to add to the repository and waiting for you to add a meaningful log message for the commit (see: Figure 14).
AnkhSVN already left out the directories: bin, obj and their content as well as files: DummyProject.csproj .user and DummyProject.Tests.csproj.user that you had to manually uncheck when using TorotoiseSVN.
Write something like: ‘Added Visual Studio solution‘ and click the Commit button.

Figure 14. AnkhSVN: provide username and password.

Upon clicking the OK button a window showing the progress will appear and, upon success, the solution explorer will be updated with green icons before the names of versioned items (see: Figure 15).

Figure 15. AnkhSVN: Solution explorer.

Now that AnkhSVN is enabled for this solution, each time you add a new item to a project it will be marked with a plus icon to let you know that the file is marked to be added to versioning (see: Figure 16).

Let’s see it in action by adding a new item in solution explorer:
right-click on DummyProject and choose: Add –> Class, leave the default name (should be Class2.cs) and click the Add button.

Figure 16. AnkhSVN: Solution explorer with new item.
Thanks to AnkhSVN integration you do not have to explicitly mark the new item as added. You simply need to right-click on solution and choose: commit.
Figure 17. AnkhSVN: commit new item.

If you want to only mark the new item as added for Subversion just right-click on the solution in solution explorer and choose: Subversion –> Add… a new window will open, whose title is: Select items to add.
It contains the list of new files in the current solution, each prefixed by a checkbox.
They are all checked by default, meaning that they will be scheduled to be added to versioning if you will click OK.

Figure 18. AnkhSVN: new item mark as added for Subversion too.

After choosing OK the Class2.cs file in solution explorer will have a yellow plus icon beside (see: Figure 19), meaning that it is scheduled to be added at the next commit.

Figure 19. AnkhSVN: new item added to versioning.

Right-click the solution item and choose: Commit Solution Changes…. The Commit dialog will open as in the first scenario, but with the file marked as: ‘Added’ instead that ‘New’.

Provide a meaningful message and click the Commit button (see: Figure 20).

Figure 20. AnkhSVN: solution explorer upon commit.

7. Install Subversion as a Service

If you want to Install Subversion as a Windows service you can use the utility: sc.exe, where sc stands for “Service Control”.
Below you find a sample batch script to automate the install process.
You can copy into a text file and save it, for example, as InstallSvnService.bat.
Open a command prompt in the directory in which you placed the .bat file and run it by digiting
InstallSvnService and pressing return.
The service will be installed and configured to start automatically.

sc create svnserve ^
binpath= "\"C:\Program Files\Subversion\bin\svnserve.exe\" -r ^ \"C:\develop\test\repo\" --service" ^
displayname= "Subversion" ^
depend= Tcpip ^
start= auto

Note that the caret symbol (^) in the script code is the line continuation character for batch scripts. It allows us to split the long command in multiple lines in order to make it more readable.
The line continuation character tells to the command interpreter that the current command is not ending at the first newline but is going on in the next line.

It’s possible that you need to change the path:
“C:\Program Files\Subversion\bin\svnserve.exe” depending on where is your copy of Subversion installed.
The path: “C:\develop\test\repo\” in the example is the path to the location in which svnserve will find the repositories to host.
Once the batch file has run open the administrative panel for services to make sure that the Subversion service exists and is running:
go to: Start –> Administrative Tools –> Services
scroll down looking for a service named Subversion and if it is not running click on the Start link.

→ top of post
→ top of paragraph

Leave a Reply

%d bloggers like this: