Click here to Skip to main content
15,868,065 members
Articles / Operating Systems / Windows
Article

Source Control with Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
4.78/5 (35 votes)
18 Oct 2007CPOL8 min read 247.6K   120   42
How to integrate TortoiseSVN – a Subversion Source Control system with Visual Studio .NET
Screenshot - image000.jpg

Introduction

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.

Background

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 Installation

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

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.

Image 2

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…

Image 3

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…

Image 4

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.

Using TortoiseSVN

Every file and folder in a "working" folder has icon overlay indicating a status of this file or folder:

Image 5

When you Right Click on a "working" folder, TortoiseSVN will give you a whole new set of options:

Image 6

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 TortoiseSVN functionality.

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:

  1. 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.

    Image 7

    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.

  2. 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 TortoiseSVN for 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.

  3. 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.

    Image 8

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.
  • Bug: 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).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionVisual Studio 2010 shows no Subversion menu Pin
Member 107254604-Apr-14 9:32
Member 107254604-Apr-14 9:32 
QuestionHow to use Gary's? Pin
satrio_budidharmawan8-Oct-12 18:55
satrio_budidharmawan8-Oct-12 18:55 
GeneralMy vote of 5 Pin
bluesathish13-Sep-12 2:29
bluesathish13-Sep-12 2:29 
GeneralGreat article! Pin
dot-net-dude23-Aug-12 13:44
dot-net-dude23-Aug-12 13:44 
GeneralMy vote of 5 Pin
Anurag Gandhi2-Apr-12 23:11
professionalAnurag Gandhi2-Apr-12 23:11 
GeneralMy vote of 5 Pin
invincibleruler12321-Jan-11 9:55
invincibleruler12321-Jan-11 9:55 
AnswerWatchout when using local file paths when importing to a Repository Pin
lighttrainmedia29-May-09 15:54
lighttrainmedia29-May-09 15:54 
GeneralLocal hosting but downloadable over internet Pin
Darkas27-Nov-07 10:28
Darkas27-Nov-07 10:28 
AnswerRe: Local hosting but downloadable over internet Pin
Ruslan Sudentas7-Nov-07 10:47
Ruslan Sudentas7-Nov-07 10:47 
Simple: install SVN, use you PC as a server, make it available on the web (search for "dynamic dns"), make sure that proper ports are open in your firewall (search for "svn port") - and you are done.
But why bother? If you are doing a commercial project, you should be able to find a way to pay $4-$7 a month in any country. And for Open Source it's free.
AnswerRe: Local hosting but downloadable over internet Pin
Karl-Johan Sjgren14-Nov-07 21:00
Karl-Johan Sjgren14-Nov-07 21:00 
GeneralConnectivity to SVN from VS.NET Pin
nwfrog26-Oct-07 12:27
nwfrog26-Oct-07 12:27 
GeneralRe: Connectivity to SVN from VS.NET Pin
adimas24-Nov-07 7:13
professionaladimas24-Nov-07 7:13 
GeneralThe Power of Subversion! Pin
Michael McKechney23-Oct-07 4:03
Michael McKechney23-Oct-07 4:03 
QuestionGreat Article and some Questions Pin
Apocwhen18-Oct-07 23:59
Apocwhen18-Oct-07 23:59 
AnswerRe: Great Article and some Questions Pin
Ruslan Sudentas19-Oct-07 4:48
Ruslan Sudentas19-Oct-07 4:48 
GeneralRe: Great Article and some Questions Pin
Apocwhen19-Oct-07 6:04
Apocwhen19-Oct-07 6:04 
AnswerRe: Great Article and some Questions Pin
Rolf Kristensen22-Oct-07 22:05
Rolf Kristensen22-Oct-07 22:05 
GeneralExcellent Pin
canozurdo18-Oct-07 6:24
canozurdo18-Oct-07 6:24 
GeneralRe: Excellent Pin
Ruslan Sudentas18-Oct-07 6:31
Ruslan Sudentas18-Oct-07 6:31 
GeneralRepository and test server locations Pin
Ratface2315-Oct-07 21:31
Ratface2315-Oct-07 21:31 
GeneralRe: Repository and test server locations Pin
Ruslan Sudentas16-Oct-07 4:35
Ruslan Sudentas16-Oct-07 4:35 
GeneralRe: Repository and test server locations Pin
Ratface2316-Oct-07 4:41
Ratface2316-Oct-07 4:41 
GeneralRe: Repository and test server locations Pin
Roger Bamforth16-Oct-07 5:21
Roger Bamforth16-Oct-07 5:21 
GeneralSourceSafe days have gone! Thanks Subversion! Pin
lonifasiko15-Oct-07 21:01
lonifasiko15-Oct-07 21:01 
GeneralRe: SourceSafe days have gone! Thanks Subversion! Pin
Ruslan Sudentas16-Oct-07 4:09
Ruslan Sudentas16-Oct-07 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.