Connect to TFS Team Project C# Code

Connect to TFS Team Project C# Code

TFS Test API
11 Shares
Connect to TFS Team Project C# Code

I am going to create a series of blog posts that explain how to use the internal Microsoft Test Manager TFS API using C# code.
The first thing you have to do in order to use the Test Manager API is to add references to the Microsoft TFS DLLs. Most of them are available only after the installation of Visual Studio 2012/2013 and Microsoft Test Manager, which is included only in the Test, PRO, Premium and Ultimate versions of the product.
The default path to the most of the DLLs that you will need is the following: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v2.0\
Most of them are available in the GAC but if you are going to use your application on a machine where the Visual Studio is not installed probably you should consider the idea to create a NuGet package for the needed DLLs.

Connect to TFS Team Project C# Code

In order to begin, first you need to create a C# class in your project and add the following code:

If you want to connect to the TFS Team Project with hard coded values you can use the following code:

First you initialize new URI object with your team collection URL which is equal to your TFS URL plus your team collection name. After that, you should create a collection object and initialize it with the URI. You use “GetService” method to initialize the TFS service. Then you can get the team project from it.

Connect to TFS Team Project using TeamProjectPicker Dialog

Collect TFS Settings with TeamProjectPicker Dialog

In order to capture the needed connection information, you can add TeamProjectPicker object to your windows app. You can use its method “ShowDialog” in order to collect the information.

Next you can read how to use TFS test plans using C# in my next article.

  • Aarathi

    How do I connect my Visual Studio with TFS online test cases?

  • Vedha

    I am getting the following error when I connect to TFS 2013 with VS 2017 .

    Unable to load WITDataStore32.dll. Can you please help to resolve the issue