Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Studio SDK
 How to: Use the TFS SDK to Write Co...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
 
How to: Use the TFS SDK to Write Code 

The following procedure shows you how to write code with the Team Foundation Server SDK. It shows you how to create the project, add the appropriate assemblies, and then compile and run the code.

To Create the Project

  1. Start Visual Studio.

  2. Do one of the following:

    • On the File menu, click New, then click New Project.

    • Press Ctrl+Shift+N, and the New Project dialog box will appear.

  3. In Project types, expand the Visual C# node, then select Windows.

  4. In Templates, select Console Application.

  5. In Name, type TfsApplication1.

  6. Click OK.

To Add the Appropriate Assemblies

  1. On the Project menu, click Add Reference.

  2. In the Add Reference dialog box, click the .NET tab.

  3. Select Microsoft.TeamFoundation.Client, and then Microsoft.TeamFoundation.WorkItemTracking.Client.

    If these assemblies are not listed, click the Browse tab to locate these assemblies. Add them to the project. The assemblies should be in the Windows directory, in the "assembly" folder.

  4. Click OK.

To Compile and Run the Code

  1. Copy and paste the example code to replace the default code in Program.cs

  2. Do one of the following:

    • On the Debug menu, click Start Without Debugging.

    • Press Ctrl+F5.

  3. When prompted, enter the friendly name or URI of a valid Team Foundation Server.

Example

This Code Example will connect to the Team Foundation Server, connect to the WorkItemStore, and then list the projects available on the Team Foundation Server.

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

namespace TfsApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Let the user choose a TFS Server.
            Console.Write("Please enter a valid TFS Server or URI: ");
            String tfsServer = Console.ReadLine();
            tfsServer = tfsServer.Trim();

            // Connect to the TeamFoundationServer.
            Console.WriteLine();
            Console.Write("Connecting to Team Foundation Server {0}...", tfsServer);
            TeamFoundationServer tfs =
                TeamFoundationServerFactory.GetServer(tfsServer);

            // Connect to the WorkItemStore.
            Console.WriteLine();
            Console.Write("Reading from the Work Item Store...");
            WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            // Display the details about the TeamFoundationServer.
            Console.WriteLine("\n");
            Console.WriteLine("Team Foundation Server details");
            Console.WriteLine("Server Name: " + tfs.Name);
            Console.WriteLine("Uri: " + tfs.Uri);
            Console.WriteLine("AuthenticatedUserDisplayName: " + tfs.AuthenticatedUserDisplayName);
            Console.WriteLine("AuthenticatedUserName: " + tfs.AuthenticatedUserName);
            Console.WriteLine("WorkItemStore:");

            //  List the Projects in the WorkItemStore.
            Console.WriteLine("  Projects.Count: " + workItemStore.Projects.Count);
            foreach (Project pr in workItemStore.Projects)
            {
                Console.WriteLine("    " + pr.Name);
            }
        }
    }
}

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Adding Assemblies      deruss79   |   Edit   |   Show History

The references were not available in the .NET tab, and I was unable to add references directly from the GAC (\Windows\assembly).

The Team Foundation assemblies can be found in \Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\. Adding from here works.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker