by Ewald Hofman
3. December 2009 20:28
This is the first post in a series that describes how you can work with the TFS Object Model, API or SDK. In this first part we will open a connection to the team project collection that opens the ability to access all artifacts of TFS.
Create a new project and add the following references to your project:
- Microsoft.TeamFoundation.Client.dll
- Microsoft.TeamFoundation.Common.dll
You can find the dll’s in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0
Then you have to add the following using statements:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
You can now open the connection with the following code:
// The url to the tfs server
Uri tfsUri = new Uri("http://localhost:8080/tfs/");
// Load the tfs instance
TeamFoundationApplicationInstance tfai = new TeamFoundationApplicationInstance(tfsUri, new UICredentialsProvider());
// Log in to TFS
tfai.EnsureAuthenticated();
// Get the default project collection
TeamProjectCollection tpc = tfai.GetService<ITeamProjectCollectionService>().GetDefaultCollection();
The following posts will describe how to access the rest of the artifacts (work items, version control and team build) in the TFS SDK.
All code examples are based on Beta 2 and are subject to change.