0

我正在尝试从 TFS Online 获取项目列表。我没有收到任何异常,但 tpcNodes 集合计数始终为 0,因此它没有列出任何项目。

public List<string> GetProjects()
        {
            string _myUri = "https://testredrock.visualstudio.com/defaultcollection";
            List<string> projects = new List<string>();
            NetworkCredential netCred = new NetworkCredential("userName", "password");
            BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
            TfsClientCredentials credential = new TfsClientCredentials(basicCred);
            credential.AllowInteractive = false;
            string TFSServerPath = host;

            using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(TFSServerPath), credential))
            {
                tfs.EnsureAuthenticated();

                CatalogNode catalogNode = tfs.CatalogNode;
                ReadOnlyCollection<CatalogNode> tpcNodes = catalogNode.QueryChildren(
                                new Guid[] { CatalogResourceTypes.ProjectCollection },
                                false, CatalogQueryOptions.None);
                foreach (CatalogNode tpcNode in tpcNodes)
                {
                    Guid tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]);
                    // Get catalog of tp = 'Team Projects' for the tpc = 'Team Project Collection'
                    var tpNodes = tpcNode.QueryChildren(
                              new Guid[] { CatalogResourceTypes.TeamProject },
                              false, CatalogQueryOptions.None);
                    foreach (var p in tpNodes)
                    {
                        projects.Add(p.Resource.DisplayName);
                    }
                }
            }
            return projects;
        }
4

1 回答 1

0

我建议您使用TfsTeamProjectCollectionFactory.GetTeamProjectCollection它来访问您的项目。

于 2013-11-15T14:18:52.033 回答