Setting up a SVN project

Learning how to use SVN properly is a difficult task. But don’t be afraid! Here I want to teach you a good pattern for using SVN with Visual Studio projects. It is important to seperate source code, interim build files, build output, vendor directories and include headers properly from each other. Ever heard of SVN properties? We use them to exclude compiler generated files and link dependency-repositories (svn:externals) from your daily commit window, so that you only see the important things. You will end up falling in love with SVN.

Requirements

We are going to need the following components in this tutorial. Once you understand this pattern you will be able to replace them if desired.

Step 1: Finding a Host

Finding the right host for your project can be difficult. There are multiple categories of hosts available:

  • some work using an approval system; you must provide quality
  • others limit your time to a trial
  • or they grant you a tiny team + tiny repo maximum size

In my opinion, OSDN is the best place to be hosted at so try to get a project here. If you are denied then try to look up using “best free SVN” or “list of source code hosts”.

Step 2: Creating the Repository

Try creating a SVN repository at your host. It should come with appropriate documentation on how to do so.

Check-out URL

In your SVN settings you should find a “check-out” URL. Copy it into your clipboard.

TortoiseSVN Checkout Window

Select a directory location where you want to check-out your project in. Then right click into the folder and select “SVN Checkout”. You should see the Checkout dialog open up.

  • URL of repository: paste in the “check-out” URL that you copied from your SVN host
  • Checkout directory: make sure it points into a new folder inside of your desired repo location

Leave everything else as is. When finished, click OK. You will be asked for username and password. Put in the credentials that you registered with at your SVN provider. If it does not ask for credentials then you will have to put them in once you start pushing code into the repository (soon ☺).

Step 3: Establishing the Directory Template

There are two templates I want to teach you. On the left you see a binary template and on the right a library template.

Directory Template Binary Directory Template Library

Binary Template: This template is used for DLL and EXE files.

  • bin: executable build results in various configurations and platforms
  • build: Visual Studio project configuration files and helpers
  • obj: interim compiler and linker files for building
  • src: executable code folder
  • vendor: external dependencies; either third-party or code you share across projects

Library Template: This template is used for LIB files.

  • include: public headers for projects that will use your SVN repo as vendor
  • lib: executable-dependency build results in various configurations and platforms; like “bin” but not directly executable

Even though those templates are similar they must be separated. The include and src folders should be treated the same in this tutorial. We are going to focus on the Binary Template.

Now we want to change the actual repository. Select all folders that we created, right click and hit the option “TortoiseSVN -> Add”. This will mark the folders for addition during next commit and enable properties for them.

dir+obj Settings

Select the “bin” and “obj” folders, right click on them and hit “Settings”. In the Windows dialog select the “Subversion” tab. This tab is provided by the TortoiseSVN shell extension to simplify a lot of things. We want to click on “Properties…” next.

dir+obj Ignore

You should see an empty list of Properties. Click on “New…”. The dropdown shows many possible SVN properties for application. Our goal is to ignore all content from inside of our selected folders. So select the “Other” option. Fill out the dialog as shown above and click OK on both the dialogs.

This is how you modify SVN properties of folders!

Step 4: Linking the Dependencies

Inside of the “vendor” directory you should put all projects that you want to use but are a direct product of this repository. It is recommended that those projects are hosted on separate repositories. If they are hosted on another SVN repository right click on the “vendor” directory and add a new “Externals” property.

Vendor Externals

Make sure you add the vendors into correct local paths and their up-to-date remote SVN URL. Once you are finished adding go to your SVN root folder, right click into it and hit “SVN Update”. TortoiseSVN will fetch all externals into their folders automatically.

Step 5: Creating the Visual Studio project

I assume you know how to develop applications using Visual Studio. So launch the IDE and create an empty project inside of the “build” folder of our repository.

MSVC Empty Project Creation

  • make sure you disable the option to create a solution-based directory; it is a bad option that creates unnecessary complexity
  • name your project appropriately; changing this name afterward is tedious
  • properly select the output location as “build” folder of your repository

Once ready click on “OK”. It should create a new folder inside of “build” called after the project name. We do not want that. Go into that folder, select all files, ctrl+x to cut, go into “build”, paste the files into “build” and delete the unnecessary folder.

Now it is time to set up the Visual Studio project itself. Remember how we created “bin” and “obj” folders? We have to instruct Visual Studio to use them. Launch the solution file of your project and open the project properties.

MSVC Project Properties

Make sure that you select All Configurations and All Platforms. Then change the following properties.

  • Output folder: set to $(ProjectDir)..\bin\$(Platform)\$(Configuration)\
  • Interim folder: set to $(ProjectDir)..\obj\$(Platform)\$(Configuration)\

Optionally, it is recommended that you enable the static CRT.

If you added vendors then now is the time to add include paths and add library paths to them as relative paths. It is especially simple to do if all your vendors use the same rules as in this tutorial, for example.

MSVC Additional Library Paths

The zlib project does use the same template. Because of that you can use the $(Platform) and $(Configuration) macros to select the correct lib version.

MSVC Additional Dependencies

After that you have to add the .lib files as Additional Dependencies under Linker -> General. For all projects that use our template you can simply add “*project_name*.lib”.

Congratulations! Now your project is ready to compile source code!

Step 7: Add Source Code

Before you can add include directories you need to add C++ files to flag the project as C++ project. It is recommended to start off with a main.cpp file and a main.h file. To add them to Visual Studio simply drag+drop them on the project.

When adding source code remember to right click and perform “TortoiseSVN -> Add” on the files! Never forget to push source code into the remote codebase.

Step 8: Commit your Codebase

Once you are confident that everything is compiling correctly it is time to push the code to our SVN host.

SVN Commit

Right click into the root folder of your repository and select “SVN Commit”. In this dialog you see the current status of your SVN working copy (file list). Take your time to review the changes. Make sure your Commit will not break anything. Give your Commit a meaningful message. And then click “OK”.

Done!