public List<string> ListAllProjects(){
TeamFoundationServer teamFoundationServer =
TeamFoundationServerFactory.GetServer(@"http:\\ld-tfs08sp1:8080\\");
teamFoundationServer.Authenticate();
WorkItemStore workItemStore = new WorkItemStore(@"http:\\ld-tfs08sp1:8080\\");
List<string> list = new List<string>();
foreach (Project pr in workItemStore.Projects)
{
list.Add(pr.Name);
}
if (list.Count == 0)
list.Add("Not Found");
return list;
}
答案 0 :(得分:17)
以下示例将检索TFS 2010中给定团队项目集(TPC)的团队项目列表:
static void Main(string[] args)
{
var results = GetTfsProjects(new Uri("http://mytfsserver:8080/tfs/DefaultCollection"));
}
private static List<string> GetTfsProjects(Uri tpcAddress)
{
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcAddress);
tpc.Authenticate();
var workItemStore = new WorkItemStore(tpc);
var projectList = (from Project pr in workItemStore.Projects select pr.Name).ToList();
return projectList;
}
希望这有帮助。
答案 1 :(得分:2)
试试这个
var TeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(teamProjectCollectionUrl);
var commonStruct = TeamProjectCollection.GetService<ICommonStructureService>();
var teamProjectInfos = commonStruct.ListAllProjects();
祝你好运