Getting started with VisualSVN
The previous post explained the basics of using Subversion. We used TortoiseSVN from the Windows shell, and while this was really easy to do it isn’t always the most convenient. Luckily for us, there are ways to integrate Subversion with most of the popular IDEs. Since I primarily use Visual Studio, this post will explain how to use a plugin called VisualSVN to manage your repository without having to leave Visual Studio.
VisualSVN is simply a front-end for the command line Subversion functions, just like TortoiseSVN. The difference between the two is that TortoiseSVN is a “add-in” for Windows and VisualSVN is an add-in for Visual Studio. However, VisualSVN uses TortoiseSVN for its functions, so really VisualSVN is just another way to use TortoiseSVN. To explain: TortoiseSVN allows you to access Subversion functions from Windows with a nice GUI, and VisualSVN allows you to access TortoiseSVN from within Visual Studio.
There are a few other Subversion add-ins for Visual Studio out there, the most popular probably being AnkhSVN. AnkhSVN is great, but in my experience it’s a little more complicated that what most people need.
To get started we’ll first need to download VisualSVN. A 30-day full-featured trial is available, and if you participate in an open-source project you can get a license for free! Even if you don’t qualify for the free license, I would highly suggest checking out this great piece of software – once you get used to it you’ll love it.
I’ll brush over the actual installation, but note that if you have multiple versions of Visual Studio installed, VisualSVN will work with them all (except for the free Visual Studio Express Editions). Just a quick review before we get into the details – the following programs are needed for everything to work:
After you install VisualSVN and open Visual Studio, you’ll notice the VisualSVN menu. This menu will soon become one of your best friends, but first you’ll might have to fight with it a bit. To minimize this fighting, I’ll explain how to set up a new VisualSVN-enabled web site.
A VisualSVN Enabled Web Site
You’ll have to set up your directories a little differently than you are used to if you want to use VisualSVN with a web site project. To begin, you need to create an empty Visual Studio solution. Usually web sites don’t need or use solution files, but to make the “Get Solution from Subversion…” function to work nicely we’ll need a solution file to get.
Select “File >> New Project…” in VS, and find the “Blank Solution” project type. This will create a solution that we can later add projects to. For this example I’ll name my solution “SVNWebSite”. I’m going to use C:\TeamProjects, which already contains a few solutions in subfolders. Before you hit OK, make sure the “Create directory for solution” checkbox is checked.
Now we have an empty solution with a solution file located at C:\TeamProjects\SVNWebSite\SVNWebSite.sln. Next we need a web site, but it needs be located in a sub-directory of C:\TeamProjects\SVNWebSite\. This has to be the case to make VisualSVN work nicely. You’ll find some other hacks around this issue, but from what I’ve seen a sub-directory is the easiest.
Right-click in the Solution Explorer and select “Add >> New Web Site…”. I’ll place the site in a directory called “Web”, the full path being C:\TeamProjects\SVNWebSite\Web, with “File System” selected for the location.
Now we have a solution containing a web site, but nothing is yet in a Subversion repository. Note that we even haven’t used Subversion, TortoiseSVN, or VisualSVN yet! Well, now is the time. To import your solution into a Subversion repository, select “Add Solution to Subversion…” from the VisualSVN menu. I’m going to select “Add to a New Repository” and place it at C:\My Repositories\SVNWebSite. You can leave the “Working copy root folder:” setting alone.
Our repository has been created and the working copy directory has been set, but we have one more step to complete before the files are actually added to the repository. Select “Commit…” from the VisualSVN menu, enter a comment, and press OK.
Now our files are finally in a repository! You can now to a commit at any time to take a snapshot of your solution. You can treat this just like any other solution – opening, closing, adding files, etc. all work the same.
A few extra notes:
- You can now work on a web site as a team. Once the previous steps have been done, anyone with access to the repository you created can simply use “Get Solution from Subversion…” from the VisualSVN menu. This will get a “working copy” of the solution so it can be developed locally. Once a team member makes a change, they do a Commit and the other team members run an Update, both of which can be accessed from the VisualSVN menu. This way each developer has their own local version of the site, but it stays up to date with other developers changes when Update is run.
- You can delete the solution and project directory (but don’t delete the repository!) from your projects directory to archive old projects. To work on them again, simply use “Get Solution from Subversion…” from the VisualSVN menu.
- You can have multiple versions of the same site. To do this, create a branch using the “Branch…” function and put it in a location like file:///C:/My Repositories/SVNWebSite/branches/, which was created automatically for you. You can then use “Get Solution from Subversion…” to check out the branch, or the trunk, or check them both out and place them in different locations.
- You can still administer the repository using TortoiseSVN from the Windows shell.