Integrating Subversion into Visual Studio

Today I'd like to talk about integrating Subversion into Visual Studio. Subversion (commonly referred to in the abbreviation SVN) is a great source control management system, used by many open-source projects, as well as many small to medium companies. Since it's IDE agnostic, it doesn't have native integration into Visual Studio, or any other IDE for that matter, although many IDEs do support it directly (e.g. SharpDevelop, Eclipse). While the official client for SVN is a command line tool, most Windows developers use TortoiseSVN, which works as a Windows Explorer extension and provides an easy to use GUI for SVN. Still, it's not very comfortable to switch back and forth from Visual Studio to Windows Explorer all the time.

There are three options I'd like to talk about here:

VisualSVN is a commercial tool, which costs $79 a seat (free for personal use or open-source projects, or if you're a Microsoft MVP), which integrates SVN into Visual Studio by using TortoiseSVN GUI from inside Visual Studio. When you commit ("check-in"), update ("get latest version") or view history, VisualSVN opens the respective TortoiseSVN dialog to do the job. This has the benefit of using the same familiar GUI both inside Visual Studio and outside of it. It also follows changes in the file system, such as if you move, rename or delete a file in Solution Explorer, and updates the Working Copy (that's an SVN term meaning your local SCM-controlled code) with the changes, so that you can easily commit these changes. It also has other nice features, like replacing the green bar at the edge of the code editor with it's own bars, which indicate changes made to the file since the last update, and not just since you last opened it. It can also easily jump from change to change in the file, using Ctrl + up/down arrow.

Another option is AnkhSVN, a free and open-source project which recently received support from Microsoft, and is a full-featured client for SVN. I personally find it not as easy to use as TortoiseSVN. For example, its diff tool is much weaker (but you can configure it to just use TortoiseSVN's diff tool), and it's commit UI has a too-small text box to enter comments, plus it doesn't have a spell-checker and auto-complete code elements like TortoiseSVN does.

The last option is for people who want TortoiseSVN in their Visual Studio, but can't use VisualSVN for some reason, e.g. it's too expensive or they have the Visual Studio Express edition, which doesn't allow plugins. Simply put, this option adds the calls to TortoiseSVN tools to Visual Studio as external tools, available from the Tools menu, and you can also create a toolbar with these tools for easy access.

My personal preference is for VisualSVN if possible, and a combination of AnkhSVN and TortoiseSVN external tools otherwise. This allows AnkhSVN follow and update file-system changes, while interaction with the SVN server is done with TortoiseSVN.

Back in 2007, a guy named Garry Bodsworth created a VBScript which automatically installs these external tools, together with some Visual Studio settings files which created a nice toolbar with icons. At the time, Visual Studio 2008 was the latest release, and those settings files have not been updated since. They may or may not work with later versions of Visual Studio. The VBScript does work, but only with commercial versions of Visual Studio. For some reason, the Express editions use a different registry key, so the script has to be modified to add the external tools to these editions.

I took the liberty to update the script, both to make it work with more recent versions of Visual Studio (which boils down to adding comments with the vesion numbers of recent vesions) and to make it work with the Express editions. I also improved it a bit, so that when you do a diff on the current file, the diff window will open scrolled to the current line in the code file. After running the script, the new tools will be available through the Tools menu of Visual Studio.You will still need to add a new custom toolbar and add them as buttons, if you wish.

here's a link to my version of the script. If you can improve on Garry's original settings files, or verify that they work with recent versions of Visual Studio, I'd be happy to update this post about it.