Udostępnij za pośrednictwem


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

empty-folder
vstfs:///Classification/TeamProject/313a9cf6-a2b9-4f03-9fd4-73fbc22aaf80
[WellFormed]

no-folder
vstfs:///Classification/TeamProject/f76c2d64-6029-4292-8b99-91ba8fbb5ba9
[Deleting]

branch-of
vstfs:///Classification/TeamProject/b29bb5a2-f921-4f10-a281-b845192427c3
[WellFormed]

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>");

                Environment.Exit(1);

            }

            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}]",

                                 
projectInfo.Name,

                                 
projectInfo.Uri,

                                 
projectInfo.Status);

            }

        }

    }

}

 

[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
Microsoft.TeamFoundation.Client.dll

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

 

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 :)

ListTeamProjects.zip

Comments

  • Anonymous
    February 07, 2006
    This post builds off my Simple Team Foundation Server Object Model Application post.  Also, I am currently...
  • Anonymous
    August 12, 2006
    I recently had to put together a list of links to code samples.&amp;nbsp; This isn't even close to comprehensive,...
  • Anonymous
    August 12, 2006
    I recently had to put together a list of links to code samples.&amp;nbsp; This isn't even close to comprehensive,...
  • Anonymous
    September 06, 2006
    La arquitectura de Team Foundation esta orientada a servicios, no en el sentido que utiliza servicios
  • Anonymous
    February 26, 2007
    I know, the title sounds a little odd. :) Got a question in the forums : i need to make sure that all