Wednesday, May 2, 2012

Setup your first TFS LinqPad query

 

Prerequisites

  • LinqPad (of course)
  • Team Explorer (as part of your complete VS2010 installation)

Setup

  • Inside LinqPad create a new empty query and in the Language combo box select C# Statements.

    image
    • Go to the Query Properties page by the Query menu or by pressing F4.
    • You can add assembly references using two ways in the Additional References tab, by browsing or adding them from the GAC

      image

      Adding assembly reference by browsing
      • Press the Browse button
      • The assemblies we want are under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.

        image

        Adding assembly references by adding from the GAC
        • Press the Add button
          • Check the Show GAC assemblies option
          • Enter TeamFoundation in the textbox

        image

        Usually we need at least:
        • Microsoft.TeamFoundation.Client.dll
        • Microsoft.TeamFoundation.Common.dll
        But we might also want:
        • Microsoft.TeamFoundation.VersionControl.Client.dll
        • Microsoft.TeamFoundation.Build.Client.dll

          image

          Now, in the Additional Namespace Imports add the following lines
          • Microsoft.TeamFoundation.Client
          • Microsoft.TeamFoundation.Framework.Client
          And maybe those too
          • Microsoft.TeamFoundation.VersionControl.Client
          • Microsoft.TeamFoundation.Build.Client
          Finally press Ok
          We are now ready to write our first query

          A first query

          Let’s start with something simple
          var tfs = TfsTeamProjectCollectionFactory
              .GetTeamProjectCollection(new Uri("http://localhost:8088/tfs"));
          
          tfs.Dump();
          

          Now press F5 and you should get a result like below

          image

          That’s it.  You are now ready to start writing useful LinqPad queries against your TFS server.

          What's next


          You should take a look at useful queries I wrote using LinqPad and the TFS API here.

          1 comment:

          MADCookie said...

          Thank you for posting this. It is very well written and eliminated some confusion I had. In particular, it was difficult to find the DLLs for the LINQPad references. So many Microsoft forums had a path didn't include the DLLs. Your idea of referencing the GAC was the key I hadn't considered.

          Thanks!!