I'm trying to get list of projects from TFS Online. I'm not getting any exception but the tpcNodes collection count is always 0, so it does not list any projects.
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;
}