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

Binding a HTML-formatted string to a WPF WebBrowser control

Sometimes there is a need to display a HTML formatted string in a WPF application. There are a couple of ways to do this, but the most stright forward is to use a WebBrowser control and the NavigateToString method. This approach has one big flaw, you cannot use binding to a string out of the box, but I found a great solution through Stack Overflow which adds a bindable property to the  WebBrowser  control using  NavigateToString . The following class is all that is needed to add that behavior. A new depencency property named Html is introduced to the  WebBrowser  and the proper change action is performed in the OnHtmlChanged method. public class BrowserBehavior { public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached( "Html", typeof(string), typeof(BrowserBehavior), new FrameworkPropertyMetadata(OnHtmlChanged)); [AttachedPropertyBrowsableForType(typeof(WebBrowser))] public static string GetHtml(WebBrowser bro

Binding Enum with DescriptionAttribute in WPF

Binding an enumeration to a ComboBox can be done in several ways. In most cases you don't want to display the value itself, but a more user friendly description. One common approach is to use the DescriptionAttribute on the Enum values to supply a description for each value.  This is all possible in a very MVVM friendly way. First step is to add the  DescriptionAttribute  to the values of the enumeration. public enum MyValues { [Description("First value")] First, [Description("Second value")] Second } To retrieve the description from the enum we use a simple extension method. This method returns the value of the DescriptionAttribute if it exists, otherwise the string representation of the enum value is returned. public static string GetDescription(this Enum value) { var fieldInfo = value.GetType().GetField(value.ToString()); var attribute = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as

Google+ finally for everyone!

There have been a lot of whining on Google from their Apps-users since the launch of  Google+  for everyone with a regular Google-account. The Apps-users have not been able to use  Google+ , until now! (actually  october 27 ) As usual I am impressed with most of the things Google accomplishes, but now when all of their services have gotten a visual and functional touchup I am getting really impressed. As someone at an early stage pointed out it is really sweet of Google to play naive and let me fill in my profile information when I create my profile (as if Google did not already know), but after a few clicks I am on the go. My albums from Picasa is automatically integrated and even the pictures I have uploaded to this blog is shown in  Google+ . But what happens next? Practically no one of my friends are on  Google+  so what do I use it for? I guess we will see. Hopefully there will be even more integration between the social networks in the future. I am anyhow very satified with