Skip to main content

Automatically configure Team Explorer connections

The first time you open Team Explorer to connect to Team Foundation Server there are three things that needs to be done before you can start working against the server.
  1. Register server in Visual Studio
  2. Select active projects in Team Explorer
  3. Create workspace in Source Control
I got a request if there was a way to automate these steps. Of course it can be done, but there are some light hacking involved. Here is what I cam up with:

Register server
Registered servers are easy to manage since they are saved in the registry. Given that the user has write access to the registry this step is easy to automate. The structure is as shown below, where my server is called ServerName. The key names explain themselves and this is all that is needed for Visual Studio to find the server as a registered Team Foundation Server.

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers]
"ServerName"="http://servername:8080/" 

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers\ServerName]
"Offline"=dword:00000000
"AutoReconnect"=dword:00000001

Select active projects
Active projects are saved in the Team Explorer configuration file. This is save to one of the following locations:

Windows 7
C:\Users\{user}\AppData\Roaming\Microsoft\VisualStudio\9.0\Team Explorer\TeamExplorer.config

Windows XP
C:\Documents and Settings\{user}\Application Data\Microsoft\VisualStudio\9.0\Team Explorer\TeamExplorer.config

The file only contains a list of the active projects with an URI reference. That makes it pretty straight forward to create or modify this file as you wish. This assumes that the user has write access to the specified directory.

<!--Configuration file: specifies which project are visible in the Team Explorer-->
<server_list>
    <server url="http://servername:8080/" current="yes" autoload="yes">
        <project uri="vstfs:///Classification/TeamProject/74ef7e04-e96a-4bc1-9f4f-307d92eb5666" />
        <project uri="vstfs:///Classification/TeamProject/eff01aeb-6d20-4523-a3e2-8709c88319fc" />
        <project uri="vstfs:///Classification/TeamProject/0f8f3f94-e63b-4401-aa5a-014b079e156d" />
    </server>
</server_list>

Create workspace
Creating a workspace is the only of the steps that is made by using the Team Foundation Server API. Here is a simple example of how it may look. VersionControl is a property of the type VersionControlServer that has already been initialized.

internal void CreateWorkSpace(string sourceControlPath, string localPath)
{
    if(!Directory.Exists(localPath))
    {
        Directory.CreateDirectory(localPath);
    }
    WorkingFolder[] workingFolders = new WorkingFolder[]
    {
        new WorkingFolder(sourceControlPath, localPath, WorkingFolderType.Map)
    };
    VersionControl.CreateWorkspace(WorkSpaceName, UserName, String.Empty, workingFolders, SystemInformation.ComputerName);
}

With these steps packed together in a neat little application run at logon the user never has to anything more than to start Visual Studio to get started working against the Team Foundation Server.

Comments

Popular posts from this blog

LEAP Sweden - Identity & Access Management

Today was the third day of the Swedish Lead Enterprise Architect Program at Microsoft in Kista. It has been a day filled with sessions on security and identity with a kind of unavoidable focus on federated identities in the cloud. Overall it has been an awesome day with seminars from Henrik Nilsson , Barry O'Reilly and Sergio Molero among others. A lot of Microsoft technologies was mentioned, Forefront Identity Manager , Active Directory Federation Services 2.0 , Forefront Unified Access Gateway , Direct Access ,  Windows Identity Framework and of course  Azure Access Control Service . Microsoft really has a great suite of applications regarding Identity & Access Management. I just wish there was a project or two where I could utilize all of these amazing technologies. I have had a plan to add a login feature to the Cornball using federated identities, so that might happen in the near future. Besides, Björn Eriksen provided a tip for all of us thursty for e...

The Cornball goes to Brunch with Chaplin

Lately I've been working pretty hard on different projects but not really stumbling upon anything blogworthy. The most recent project is quite interesting though, a single page, touch friendly, web application using the latest and greatest technologies. We've ended up with using Brunch with Chaplin , which is a very neat way of setting up a Backbone based single page web project with Brunch and Chaplin . Aside from this, I have my own little project that has lived on for almost 15 years already, The Cornball . From being a plain Windows application written i C an Win32 API, it has been ported to .NET using WPF, and is currently a Silverlight application hosted on Windows Azure. I could not find a better time to reanimate this project and create a new web based version, touch friendly, super optimized, awesome in any way. So I did... So please follow my journey at Github . It's going to take a while, I assure you, but I already have some ground work done. Meanwhile,...

Using ASP.NET MVC with MEF

I wrote this post almost a year ago, but never published it for some reason. Anyway, here is a little MVC/MEF magic. By default a controller in MVC must have a parameterless constructor. When using MEF a good practice is to inject the services via constructor parameters. These two in combination obviously creates an issue where the following scenario will not work out of the box, since there is no parameterless constructor for  MVC  to use. Note that the PartCreationPolicy is set to NonShared since a new controller have to be initialized for each request. [Export] [PartCreationPolicy(CreationPolicy.NonShared)] public class HomeController : Controller {     private readonly IServiceClient _service;     [ImportingConstructor]     public HomeController(IServiceClient service)     {         _service = service;     }     public ActionResult Index()     {         ...