Subversion for Visual Studio Developers

Posted by Floyd Price on March 21, 2011

Subversion for Visual Studio Developers with AnkhSVN

Accessing Subversion repositories from Visual Studio is really easy with AnkhSVN (http://ankhsvn.open.collab.net/). In this article I will illustrate just how easy it is to connect to a project in a Subversion repository and how to create a brand new project and add it to a Subversion Repository.

For this artical I’m using Visual Studio 2010 Professional however, the instructions are largely the same for all versions above 2003, I’m sure you will work it out ;-)

Installing AnkhSVN
Visit http://ankhsvn.open.collab.net/ and download the latest version of AnkhSVN, for this article I have downloaded version 2.1 but the instructions will remain the same for a while.

Configuring Visual Studio
After installing AnkhSVn you will need to tell visual studio to start using it as the Source Code Control plugin, If previously have no provider AnkhSVN will automatically become the default however if you have previously used VSS, TFS or any other Source Code Control providor you will need to change the setting inside of Visual Studio to use AnkhSVN.

Open the Visual Studio Options dialog, [Main Menu]\[Tools]\[Options]

Select Source Control and then the Plug-in Selection option from the tree.

In the drop down select “AnkhSVN – Subversion Support for Visual Studio”

Close the options Dialog and your done.

Starting from scratch

To add a new project to Subversion you will need a Subversion Repository, If your using Code Spaces for your Subversion hosting, go to your Code Spaces admin section and create a new repository.

Create a new Visual Studio project, for this article we are creating a simple MVC project, so we selected the MVC project template.

Once your happy with the project and are ready to commit it to Subversion

Right click on the Solution node in Solution Explorer and select the ‘Add Solution to Subversion’ option.

Enter the URL of the subversion repository in to the Dialog and click OK.

Enter a commit message and click OK

After a short while you will notice the Solution Explorer looks a little different, basically you have created a folder in Subversion to store your project, and you have updated your working copy by adding the files in the solution, notice the blue plus symbols (+) by the files in the solution explorer.

At this point none of your files have been commited, so once again right click on the solution node in the Solution Explorer and select ‘Commit Solution Changes’

Review the changes to be commited, unchecking any that you don’t want to commit, enter a Commit Message and hit OK.

After a short while the commit will be completed and you will notice the files in the solution explorer have a blue tick next to them, this illustrates that the are the same locally as they are on the Subversion Server.

Thats it you have created a new project and commited code to your repository. Every time you make a change locally you will notce the icon in the solution explorer changes to reflect its new state. If you working in a team you will need to perform an update before you do a commit to ensure you have the latest changes.

Finally lets verify that our code is in the Subversion Repository by opening it in the browser.

 

Tags: ,

4 comments

  1. A few additional tips that I’ve found helpful when working with AnkhSVN and Visual Studio….

    1.) The default settings may move files into your SVN repo that you’d prefer weren’t included. Local log files, output from test runs and stuff like that probably doesn’t belong in your SVN repo. You can prevent this through the use of the svn:ignore settings. For example, I use Resharper which adds a bunch of settings/config files to each solution…but I don’t want those to be stored in my SVN repositories. Using svn:ignore settings allows me to exclude such files by default. To view/add/change your svn:ignore settings, right-click the solution in Visual Studio’s Solution Explorer tab and choose “Subversion >> Solution Properties”. My own svn:ignore list is as follows:

    *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store thumbs.db Thumbs.db *.bak *.class *.exe *.mine *.obj *.ncb *.lib *.log *.idb *.pdb *.ilk *.msi* .res *.pch *.suo *.exp *.*~ *.~* ~*.* cvs CVS .CVS .cvs */Debug* */Release* */debug* */release* release Release debug Debug ignore Ignore bin Bin obj Obj *.csproj.user *.user *.tmp *.TMP *resharper* *Resharper* *ReSharper* *.gpState

    2.) For those people who use Nuget, Nuget packages and settings are stored in a solution-level folder while project-level settings are stored in a packages.config file within each VS project. Due to their location, the solution-level files are generally overlooked by AnkhSVN so if you want them included in your SVN repo, you need to specifically tell AnkhSVN to include them in source control. You can do this by right-clicking the solution in Visual Studio’s Solution Explorer tab, selecting “Subversion >> Select in Working Copy Explorer” and using the Working Copy Explorer to add the contents of the packages folder to your SVN repo.

    Hope that helps!
    - Gregg

  2. Excellent tips Gregg!

  3. Thanks, was useful

  4. Question: As I add new solutions to Subversion via Ankh Add Solution to Subversion command, can I get Ankh/Subversion to remember the URL to my repository? Tiresome to type it in each time. Thanks.

Leave a comment