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.
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!
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:
- Visual Studio doesn't let you open more than one solution, so I'm forced to chose between Project01 and Libraries (which is hardly perfect).
- Moving the Libraries projects within the Project01 Solution causes Subversion to get confused and causes a coupling of the code that would be difficult when Project02 came along.
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.
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:
- My example below includes Tests projects, these are of great value but not needed as far as this example goes (obviously).
- The Screenshots are for AnkhSVN, but the scenario works with VisualSVN. Where the stage differs, I'll endevour to explain the differences where appropriate.
- This is my current setup and I haven't run into any issues with it. However, by following this guide you are aware that I'm occasionally wrong and that gremlins may eat your data if you don't ensure that everything is working as it should.
- My working setups are Visual Studio 2008, VisualSVN Server 1.7.2 (which includes Subversion 1.6.2), TortoiseSVN and VisualSVN or AnkhSVN. Tested on Windows 7 and Windows XP.
- I'm going to suggest using the standard trunk, tags and branches layout within a repository - but you'd prefer not to it should be easy to customise.
- 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).
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.
- After adding each of the solutions, you should make sure that you "Commit" to update the server's version of the files.
Your repository should look something like the following:
/svnrepository /Project01 /trunk /Project01 /Project01.Tests /Libraries /trunk /Libraries /Libraries.Tests
- Ok, you can close Visual Studio 2008 (not sure if you need to, but I feel safer doing so).
- 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.
- Right click on the trunk of Project01 and click "Show Properties".
A list of properties (possibly including svn:ignore are shown. Click "New"
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:
Libraries http://svn.codespaces.com/amadiere/aspnet/Libraries/trunk/Libraries/ Libraries.Tests http://svn.codespaces.com/amadiere/aspnet/Libraries/trunk/Libraries.Tests/
Don't forget to type "svn:externals" into the top right hand box.
- Reopen Visual Studio and your Project01 Solution.
- 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...
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
- 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!