simple command-line example: listing the team projects on a server

This is a very simple example showing a simple use of the ICommonStructureService.


Running against my current test server shows some of the test projects I made yesterday while testing a bug fix: 


% ListTeamProjects.exe jmanning-test





using System;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.Server;


namespace ListTeamProjects


    class Program


        static void Main(string[] args)


            if (args.Length == 0)


                Console.Error.Write("Usage: ListTeamProjects <servername>");




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

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

            foreach (ProjectInfo projectInfo in css.ListAllProjects())


                Console.WriteLine("{0,-30} {1} [{2}]",









[Edit 2005-10-20]
Thanks to Tom Fieldhouse at Intel for asking - the references needed
for this to build include System, Microsoft.TeamFoundation.dll,
Microsoft.TeamFoundation.Common.dll, and

    <Reference Include="System" />
    <Reference Include="Microsoft.TeamFoundation">
    <Reference Include="Microsoft.TeamFoundation.Common">
    <Reference Include="Microsoft.TeamFoundation.Client">


The natural
question is "why don't your assembly names match the namespaces (or
vice versa)?" - unfortunately, there's various non-interesting reasons
for that, and we're hoping to make it better in V2.


[Edit 2005-10-21]
While the above code is using ListAllProjects to get all the team
projects on the server (even those not in the WellFormed state), CSS
also has a different method ListProjects() that
returns the exact same list, except it's filtered to only show the
WellFormed projects.  This is very useful when you don't want to
have to worry about your call potentially catching a team project while
it's in the middle of being created/deleted/whatever, or projects that
were only partially created 🙂

Comments (5)

  1. This post builds off my Simple Team Foundation Server Object Model Application post.  Also, I am currently…

  2. Buck Hodges says:

    I recently had to put together a list of links to code samples.&amp;nbsp; This isn’t even close to comprehensive,…

  3. Buck Hodges says:

    I recently had to put together a list of links to code samples.&amp;nbsp; This isn’t even close to comprehensive,…

  4. La arquitectura de Team Foundation esta orientada a servicios, no en el sentido que utiliza servicios

  5. I know, the title sounds a little odd. 🙂 Got a question in the forums : i need to make sure that all

Skip to main content