This article explains how to integrate
TortoiseSVN - a Subversion Source Control client with Visual Studio .NET. It is a "how to" cookbook that outlines specific steps needed to set up a functional Source/Version Control system to be used in a .NET project with all of the tools accessible in Visual Studio .NET. This assumes that the reader has a basic understanding of version control systems and will further research any of underlying concepts as well as the functionality of the tools on its own.
Why Do You Need To Read This?
The days of "Cowboy coding" are over both in software development methods and in dealing with the source code. If you think otherwise, you are less productive and will be less competitive than the other guy. The setup costs are not an excuse any more - the price is Free and this article will set you up and running in no time.
The article would lose in depth to any tutorial on the subject. But because it's short, there's less of a chance you fall asleep in the middle. And once you have a functional environment - you will discover the details yourself.
In the core of a Source Control is Versioning functionality that allows multiple developers to work on the same project, revert to previously saved versions of a file, merge changes and more. It is essential for effective team work and also highly beneficial for single developer projects (see below on benefits for solo developers).
The most common approach for larger companies is to use Visual Studio Team System along with Microsoft Source Safe (or Team Foundation Server more recently). But for smaller projects the price of these solutions could be prohibitively high, not to mention wide dissatisfaction with Source Safe among developers community.
Open source provides excellent alternatives. Subversion (SVN) is probably the most popular version control system these days.
TortoiseSVN is a Subversion client that integrates with Windows Explorer to give the user a GUI. Once
TortoiseSVN is installed it can be integrating it into Visual Studio .NET as a set of External Tools. All of this comes free.
Subversion runs on any platform imaginable. But if you plan on having your repository (the central database for your source control) on your local network - then there's no need for a separate Subversion installation,
TortoiseSVN will do it all (Well, almost. As Todd Smith points out in the comments you still need Subversion installed to have command-line tools). If you have offsite developers and need a repository on the Web, the easiest is to buy a hosting package for a commercial project or host it for free on SourceForge.net for Open Source projects. The commercial hosting is cheap: for under $10 a month you could get unlimited repositories, 2+GB of Web space and peace of mind. Search for subversion hosting and you'll get tons of offers. If you insist on installing it on your own, SVN 1-Click Setup should make installing Subversion with
TortoiseSVN a snap.
TortoiseSVN is no less than a marvellous peace of software. Get it here. Once installed (don't forget to Restart when it prompts you - it really needs it to be integrated with Windows Explorer), all of its options will be available in Windows Explorer from the Right Click menu.
Let's setup a working system for a Visual Studio .NET project.
Step 1: Repository Setup
First you need to setup a repository (the central database) for your project.
On the web: If you use Subversion hosting, use the interface of your hoster's control panel to set it up. After the setup you should have the URL of the repository as well as username and password needed for accessing it.
On the network: If you will use a repository on a (network) folder, creating it is a snap: Right Click on a folder > TortoiseSVN > Create Repository here... OK,OK.
Step 2: Upload Files (Optional)
If you've started with an empty repository and want to add files to it from a local folder, then locate a local folder with the files (let's say it's your project folder), Right Click > TortoiseSVN > Import…
You will be prompted for the URL of repository, enter the URL if you use hosted services or just a Windows path to repository folder if you are using a local network. For hosted services, it will also prompt you for username and password. Hit OK and your local files will be imported into the repository.
Step 3: Working Copy
Next step is to create a working copy – a local folder where you will be making all of your changes and that will be synchronized with a central repository. This will be your project folder. In this step the files (latest revision) from the repository will be downloaded to your local folder. To simplify, start with an empty folder, Right Click > SVN Checkout…
Enter URL or path to your repository, hit OK. The same files you've uploaded in Step 2 will be downloaded to your folder. SVN has also added some hidden files to this folder indicating that it is a "working copy" type of folder.
Every file and folder in a "working" folder has icon overlay indicating a status of this file or folder:
When you Right Click on a "working" folder,
TortoiseSVN will give you a whole new set of options:
Most commonly you will probably use "SVN Update" to get the latest revision from repository or "SVN Commit…" to upload your working copy to repository.
The focus and depth of this article make it unwise to try duplicating the wealth of documentation on how to use
TortoiseSVN. Nonetheless, you still need to read a good tutorial on this. Please refer to TortoiseSVN documentation or tutorials for finer details on
Visual Studio .NET Integration
TortoiseSVN setup would work just fine with any folder including the one with a Visual Studio .NET project. If that addresses your needs, you don't have to go any further. This is a great tool and many developers use just that. But for some it may be more productive to perform the Source Control operations inside Visual Studio .NET, without going to Windows Explorer. This is done through Visual Studio .NET add-ins. Note that the add-ins are not supported in Visual Studio .NET Express editions. That's a restriction Microsoft places on them to encourage the upgrade.
For Visual Studio .NET that support add-ins, there are three choices at the moment:
- Simplest: Garry Broadsword's Add-on
This is a marvellously simple and thin
TortoiseSVN wrapper. Download it from Garry's Web site. In Visual Studio .NET go to Tools > Import and Export Settings… and import the settings appropriate for your version of Visual Studio .NET. You will get all of the major
TortoiseSVN functionality right in Visual Studio .NET.
The only catch is that you don't get icon overlays in Visual Studio .NET, so the status of a particular file is not immediately clear. Note though that for performance reasons some users turn off the overlays in
TortoiseSVN and work happily without it. As Garry himself points out in the comments to this article:
"...[icon overlays] used to matter for me as the files were being locked with VSS so it was important to know explicitly which files were edited. With Subversion you use "edit-merge-commit" so whilst you are making your edits it doesn't matter which files have been changed, it only matters at commit time"
If you can live without overlays, this solution should be your first choice.
- Not so simple: AnkhSVN
AnkhSVN is the most comprehensive Open Source Visual Studio .NET and SVN integration. It is not just a
TortoiseSVN wrapper (in fact you don't need
AnkhSVN to work), but a separate program with functionality similar to
TortoiseSVN. Even though
AnkhSVN gives icon overlays and all of the tools appear right in Visual Studio .NET, the most common complaints with this beast are that it is slow on the projects with a lot of files, it has an unintuitive logic of how to update the files and one should be closely familiar with it to do what you want. If you aren't afraid of a challenge –
AnkhSVN is your choice. For others with less free time on their hands – consider alternatives.
- Sleek, but $49: VisualSVN
VisualSVN it is just a wrapper of
TortoiseSVN, similar to Garry Broadsword's add-on. In this case more is less, architecturally these solutions are lighter and more effective that heavy weighted "all-in-one"
AnkhSVN approach. In
VisualSVN you get your overlays and very smooth integration with
TortoiseSVN. This is simply the best choice if you don't mind paying. And even if you do, play with their trial version - you may change your mind.
Few Catches to Watch Out For
- Right after installing
TortoiseSVN do yourself a favor: go to
TortoiseSVN settings and make sure that the checkbox [Use "_svn" instead of ".svn" directories] is set. For more read here.
VisualVSN menu does not appear in Visual Studio 2005 when installed under Windows Vista. Workaround is here.
- When working in Visual Studio 2005 with Web sites as folders without implicitly creating a project file, the *.proj file gets created in the background in [My Documents\Visual Studio 2005\Projects] folder.
VisualSVN gets confused on this assuming that your Web site should reside in the same folder.
- Solution 1 (what I use): Before using "VisualSVN | Add Solution to Subversion…", go to "VisualSVN | Set working copy root…" to setup the proper location of your Web site. Since *.proj file stays outside of your working folder - it won't be included in commits.
- Solution 2 (VisualSVN recommendation):
1. Create blank solution in Visual Studio 2005 (File->New->Project->Other Project
Types->Visual Studio Solutions->Blank Solution).
2. Add Web site to the solution (File->Add->New Web Site) and specify
location for it under the same root folder as solution.
3. If the solution is located deeper than working copy root, specify
root folder (VisualSVN->Set Working Copy Root).