Multiple Subversion Projects in one Visual Studio Solution using svn:externals

Multiple Subversion Projects in one Visual Studio Solution using svn:externals

Published on: Friday, June 5, 2009 7:05:00 PM)

Cake mix:

400g of Visual Studio 2008
100g of fresh Subversion
1tsp of VisualSVN (1tsp of AnkhSVN subsitutes if you can't get hold of any).
Instructions: Put into a large bowl and beat the living-poop out of it with a spike covered hammer.

Or alternatively….

I've been quite frustrated that no matter where I looked on the web, what I searched for, which search engine I used - all the articles I found on opening multiple projects in Visual Studio (while still using Subversion), all seemed to explain only a portion of what was needed and never the full tale. So being frustrated, I decided it's the exact type of thing I needed to note here - even if it's just me that ever reads it!

The Scenario:

I have a Visual Studio solution with two projects in it: Project01 which is an MVC Web Application and the associated Project01.Tests project for testing. As I want to apply to DRY principles, I created another solution with a Class Library project (and associated test project) for putting any code that might be used again outside of the scope of the current project. This causes a couple of pickles:

I read that svn:externals was the way to go - but I didn't understand how exactly to go about this. Sometimes the guides weren't clear on how to apply the svn:externals but almost always, they weren't specifically detailing how to get the setup I wanted within Visual Studio.

The Solution:

People were right! svn:externals is definitely the way forward, but there are a few things that need to be done to get the (seemingly) perfect setup.

A few notes before we start:

The Steps

  1. You may already have this step done if you are working from an existing code base, but I started with two seperate solutions; Project01 (my application) and Libraries (my shared resource).
  2. Add both solutions to Subversion however you normally do it. For example, in AnkhSVN you right-click the solution and select "Add Solution To Subversion" and fill in the following pop-up box similar to below. Add both solutions to your SVN repository however you want.

    Add both solutions to your SVN repository however you want.

  3. After adding each of the solutions, you should make sure that you "Commit" to update the server's version of the files.
  4. Your repository should look something like the following:
  5. Ok, you can close Visual Studio 2008 (not sure if you need to, but I feel safer doing so).
  6. Open your repository browser. (e.g, right clicking on a file in Windows Explorer -> TortoiseSVN -> repo-browser. Your repository should look something like this now.
  7. Right click on the trunk of Project01 and click "Show Properties".
  8. A list of properties (possibly including svn:ignore are shown. Click "New"
  9. Within the "New Properties" window, you want to add "svn:externals" to the top right drop down box (this may not already be in the list - don't be detered). Within the main box, you want to put the name of the directory within your Project01 you want to create, followed by the URL to the repository with the code you want to fill it with : e.g:

    Don't forget to type "svn:externals" into the top right hand box.

  10. Reopen Visual Studio and your Project01 Solution.
  11. Right click the Solution name and "Update" to the latest version. You should see it add the External Library project in the text that flies past. This is basically the main part finished, but you'll spot the two Libraries projects are not visible within our solution still...
  12. Right click again on the Solution name and add an "Existing Project". Navigate to your Project01 directory and you should spot there are now 4 project directories with two of them being your Libraries projects! Simply go into them and add them one at a time.

    Adding an existing project in Visual Studio

  13. Commit your changes and you're done!

Testing Your Setup

You should be able to test your project by making changes etc to both sets of project files and committing them to your database. What should happen is your Project01 files will go to the Project01 directory in your repository and the Libraries files will still (dispite being in your Project01 solution on your development machine) be committed to the Libraries solution directory in your repository.

This setup should work for Project02 as well. Just repeat the appopriate steps and bang! - you have a fully working second project using the same Libraries!

If anyone runs into any dramatic side effects or knows of any issues with this methodology, I'd be very interested in hearing them as I'm currently on Cloud 9 with it!