Mickey Gousset

My Journey Into Team System
(Live Messenger: mickey_gousset@hotmail.com, Twitter: mickey_gousset)

Simple Team Foundation Server Object Model Application
The Team Foundation Server Object Model (TFSOM) is the public API used for interacting with Team Foundation Server. You can utilize the TFSOM to create your own client applications for interacting with Team Foundation Server. For some detailed documentation on the TFSOM, see the Visual Studio SDK. It includes documentation and sample code, showing you the variety of ways you can extend Team System.

In this post, we are going to create a simple application using the TFSOM. The plan is to then build off this sample application in future posts. For this post, we are going to create a console application, in which we create a Team Foundation Server object, and write out some of it's properties.

To get started, open Visual Studio 2005 and create a new Console application by selecting File->New->Project, and then selecting Console Application in the New Project Window. Name the project TestConsoleApp1 and click OK. If Program.CS is not already open at this point, open it.

Before we begin building the app, we need to add two references to the application:

using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;

In the Solution Explorer window, right click on References and select Add Reference. This opens the Add Reference window. Click the Browse tab, and browse to the following directory:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies

Select the Microsoft.TeamFoundation.dll and the Microsoft.TeamFoundation.Client.dll. Now add the above two "using" statements to Program.cs.

To create a new TeamFoundationServer object, you need to use the TeamFoundationServerFactory. When you use the factory, it caches an instance of the object, so that any future calls to the factory will return the same object. This should lead to improved performance for your application. To create a Team Foundation Server object, write the following line of code:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer()

So, if you Team Foundation Server is named "MSTFS", you would type:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("MSTFS")

You can also use the URL of the Team Foundation Server:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://MSTFS:8080")

The Team Foundation Server object has the following methods, attributes, and events:

MethodsAttributesEvents
AddServiceAuthenticatedUserNameCredentialsChanged
AuthenticateClientCacheDirectoryForInstance 
DisposeCredentials 
EnsureAutheticatedCulture 
EqualsHasAuthenticated 
GetHashCodeInstanceId 
GetServiceName 
GetTypeSessionId 
RemoveServiceTimeZone 
ToStringUri 

We will talk about these in detail in later posts. For now, just be aware that they are all there. Now that we have created out Team Foundation Server object, let's write out some of its attributes to the command line. Enter the following lines of code in the Main method of Program.cs:

Console.Writeline("\n" + "AuthenticatedUserName = " + tfs.AuthenticatedUserName);
Console.Writeline("\n" + "ClientCacheDirectoryForInstance = " + tfs.ClientCacheDirectoryForInstance);
Console.Writeline("\n" + "Culture = " + tfs.Culture.ToString());
Console.Writeline("\n" + "HasAuthenticated = " + tfs.HasAuthenticated.ToString());
Console.Writeline("\n" + "InstanceID = " + tfs.InstanceID.ToString());
Console.Writeline("\n" + "Name = " + tfs.Name);
Console.Writeline("\n" + "SessionId = " + tfs.SessionId.ToString());
Console.Writeline("\n" + "TimeZone = " + tfs.TimeZone.StandardName);
Console.Writeline("\n" + "Uri = " + tfs.Uri.ToString());

Save your application and compile it. Open a command prompt, and navigate to the bin/Debug folder of the project, and run TestConsoleApp1.exe. You should see something similar to this picture:

Obviously, it is not going to be exactly the same, because your server name and other attributes will probably be different. But the above image gives you an idea of what to expect.

Congratulations! You have created your first application using the TFSOM.

Here is the full code for Program.cs:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;

namespace TestConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://mstfs:8080");

	Console.WriteLine("\n" + "AuthenticatedUserName = " + tfs.AuthenticatedUserName);
	Console.WriteLine("\n" + "ClientCacheDirectoryForInstance = " + tfs.ClientCacheDirectoryForInstance);
	Console.WriteLine("\n" + "Culture = " + tfs.Culture.ToString());
	Console.WriteLine("\n" + "HasAuthenticated = " + tfs.HasAuthenticated.ToString());
	Console.WriteLine("\n" + "InstanceId = " + tfs.InstanceId.ToString());
	Console.WriteLine("\n" + "Name = " + tfs.Name);
	Console.WriteLine("\n" + "SessionId = " + tfs.SessionId.ToString());
	Console.WriteLine("\n" + "TimeZone = " + tfs.TimeZone.StandardName);
	Console.WriteLine("\n" + "Uri = " + tfs.Uri.ToString());
	
	
		
	}
	}
}

Published Tuesday, February 07, 2006 12:13 AM by mickey_gousset

Comments

# Exploring the Team Foundation Object Model@ Wednesday, February 08, 2006 12:21 AM

Mickey Gousset, a Team System MVP, is blogging about his exploration of the Team Foundation object model....

# flow1800@ Monday, July 21, 2008 1:36 PM

61Ol1t gihiroef jsgiosjiogjdso igjiosdjgiodsg jwguj 94wjsdfkj gkjgl4wg dsgds

# re: Simple Team Foundation Server Object Model Application@ Tuesday, July 29, 2008 4:47 PM

Bxt9FT  <a href="http://kfihkpxepwgc.com/">kfihkpxepwgc</a>, [url=http://jijsfjoajyma.com/]jijsfjoajyma[/url], [link=http://nufqnucldqyj.com/]nufqnucldqyj[/link], http://yjcpslrocnvn.com/

# re: Simple Team Foundation Server Object Model Application@ Tuesday, March 24, 2009 11:16 AM

Does this not work with VS 2008?

by Alex

# re: Simple Team Foundation Server Object Model Application@ Tuesday, March 24, 2009 3:34 PM

Hey Alex!  Yep, it should work with 2008 as well.

Leave a Comment

(required) 
(required) 
(optional)
(required)