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
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.
During this article I will guide you through the installation process of the following software:
Download the latest Subversion release from the download page and launch the installer. At the moment I’m writing the last available version is: svn-1.4.6-setup.exe.
Subversion will be installed under: C:\Program Files\Subversion.
Make sure that C:\Program Files\Subversion\bin is included in the %PATH% environment variable, otherwise add it following these steps:
right-click MyComputer and choose Properties –> Advanced, then click the button: Environment Variables.
Look for the name: Path between variable names (left column) in the bottom list.
Once found double click it, add a semi-colon to the ‘variable value‘ field and paste the path to Subversion bin directory (C:\Program Files\Subversion\bin).
Click ok three times to accept the changes.
Now open a command prompt and digit svn help. You should be able to see svn syntax information.
The installation succeeded. Now go on to the next step: Install TortoiseSVN
Now that you have installed it, forget it for a while and step through the next paragraphs.
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.
Create a new directory, e.g.: C:\develop\test\repo, right click it and choose: TortoiseSVN –> Create repository here… (see: Figure 1).
Accept the preselected option: Native filesystem (FSFS) at the prompt and click ok (see: Figure 2).
The new repository will be created and an informational message will tell you that ‘The Repository was successfully created‘.
Now let’s add some content. First of all prepare the standard layout: create a temporary directory next to the repo directory and call it temp: C:\develop\test\temp. Add three subdirectories inside it, named: trunk, tags, branches.
The trunk directory will become the main directory of our project and it will contain all the versioned data.
Right click on C:\develop\test\temp and choose: TortoiseSVN –> Import… and the Import window will open. Click the button on the right of the combobox: ‘URL of repository‘ (as shown in Figure 3).
A browse pop up window will open. Browse to the repository directory: C:\develop\test\repo and click OK.
The combobox will be filled with: file:///C:/develop/Test/repo.
Write the comment ‘Initial Repository Layout‘ in the ‘Import Message‘ text area at the bottom of the Import window and click OK (see: Figure 4).
Everything should be alright and the informational window shown in Figure 5 should appear. You can click OK and the repository layout is ready.
Now you can delete the temporary directory: C:\develop\test\temp.
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 12 and 13, 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 18 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).
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.
Now you can prepare your workin copy or, in Subversion language, checkout your working copy.
Create a new directory named ‘wk’: C:\develop\test\wk.
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 6).
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\wk by means of the adjacent button (see: Figure 7).
Make sure that ‘HEAD revision‘ is checked and click OK.
If you have set the ‘URL of repository‘ to svn://localhost/trunk you will be prompted for username and password (see Figure 8).
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 9).
Close that window and look inside the C:\develop\wk directory.
The wk 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.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)
Let’s add a simple text file to versioning: create a file named ‘test.txt‘ inside C:\develop\wk.
Right-click it and choose: TortoiseSVN –> Add… (see: Figure 10), 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.
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\wk and choose: SVN –> Commit… (see: Figure 11).
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.
The Log Message window will open (see: Figure 12), waiting for you to provide a meaningful message. Write: “Added empty test file” and click OK.
Make sure that everything worked fine when the informational window titled: ‘wk – TortoiseSVN Commit… Finished!‘ will appear.
It should state something like: ‘Completed At revision: 1‘.
If everything is alright then click OK.
Now you can start adding content to the file and commit the changes to the repository.
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 2005) and create a new blank solution inside C:\develop\wk.
Name the solution: DummySolution.sln and add two projects to the solution:
DummyProject.csproj and DummyProject.Tests.csproj.
The first is a Class Library project and the second is a Nunit Tests project referencing DummyProject.
If you’re using Nunit and RhinoMocks you can take advantage of the project Template I provide with the TDDTemplates.vsi (see article: Visual Studio Nunit & Rhino Mocks Templates) installer to easily create the unit tests project.
Now you can add the solution to versioning in one of two ways:
- adding the solution file and the projects directories with TortoiseSVN;
- 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.
At first select the solution file: DummySolution.sln and the two project directories: DummyProject and DummyProject.Tests.
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 13) 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: TortoiseSVN 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.
Now you can commit the freshly added content to the repository: right click on the directory C:\develop\wk and choose: SVN –> Commit… as you did when you added the test.txt file.
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 2005.
A little prompt window (see: Figure 14) will ask if you want to enable AnkhSVN for the current solution:
Click No and go to solution explorer. Right-click the solution item and choose:
Ankh –> Add solution to Subversion repository… as shown in Figure 15:
The appropriate window will pop up (see: Figure 16) asking you the repository url. Fill the URL textbox with: svn://localhost/trunk , leave ‘Create subdirectory‘ unchecked and click OK.
You will be prompted for username and password (they are managed separately by TortoiseSVN and by AnkhSVN) as shown in Figure 17.
Fill both the fields and check ‘Save credentials‘.
Upon clicking the OK button one more 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 18).
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.
A Committing progress bar will appear and, upon success, the solution explorer will be updated with green icons before the names of versioned items (see: Figure 19).
Now that AnkhSVN is enabled for this solution, each time you add a new item to a project it will be marked with a question mark icon to let you know that the file is not added to versioning (see: Figure 20).
Let’s see it in action by adding a new item in solution explorer:
right-click on DummyProject and choose: Add –> New Item…, select the Class item template, leave the default name (should be Class2.cs) and click the Add button.
If you right-click on the solution in solution explorer and choose: Ankh –> Add… a new window will open, whose title is: Select items to add (see: Figure 21).
It contains the list of non versioned 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.
After choosing OK the Class2.cs file in solution explorer will have a yellow plus icon beside (see: Figure 22), meaning that it is scheduled to be added at the next commit (the same is true for the project and solution items).
Right-click the solution item and choose: Commit…. The Commit dialog will open.
At the same time the icons beside the project and solution items become red squares (see: Figure 23), meaning that there are local modifications that need to be committed to the repository.
Provide a meaningful message and click the Commit button (see: Figure 24).
Whenever you want to quit using AnkhSVN you can disable it for the solution you are using.
Just right click the solution item and choose: Ankh –> Disable Ankh for this solution.
You can then work using TortoiseSVN or the Subversion command-line.
If you want to enable Ankh again just choose: Ankh –> Enable Ankh for this solution.
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 ^
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.