How to List TFS Team Projects using the API

As part of my TFS Bug Snapper tool I couldn’t work out how to bring up the standard “Select Server / Team Project” dialog, so I did what all good developers would do – I reinvented the wheel.

See James Manning’s post on “Listing the Team Projects on a Server” for the bits to make this happen. You can download his source here.

Essentially it comes down to this:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0]);

ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));

foreach (ProjectInfo projectInfo in css.ListAllProjects())

  // do stuff

One Comment

  1. Burton
    Posted January 17, 2007 at 5:39 pm | Permalink

    When working with WorkItems (as it appears that you were), it may be easier to use the Projects property of the WorkItemStore, as you might already have a reference to it:Using tfs As TeamFoundationServer = TeamFoundationServerFactory.GetServer("myserver")Dim witstore As WorkItemStore = tfs.GetService(GetType(WorkItemStore))For Each proj As Project In witstore.Projects ‘ do stuffNextEnd Using


Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*