c# - 如何使用 TFS 2015 上的 devops api 检索所有“项目集合”的列表
问题描述
我正在尝试使用 c# 通过 devops API 检索 TFS 2015 服务器上所有项目集合的列表。我没有直接访问 TFS 配置数据库的权限。
我发现的更多解决方案使用旧的或不推荐使用的方法,如tfsConfigurationServerFactory
class.
解决方案
您是否尝试过项目集合 API?
样品要求:
GET https://mytfsserver/DefaultCollection/_apis/projectCollections/d81542e4-cdfa-4333-b082-1ae2d6c3ad16?api-version=1.0-preview.2
示例响应:
{
"id": "d81542e4-cdfa-4333-b082-1ae2d6c3ad16",
"name": "DefaultCollection",
"url": "https://mytfsserver/DefaultCollection/_apis/projectCollections/d81542e4-cdfa-4333-b082-1ae2d6c3ad16",
"state": "Started",
"_links": {
"self": {
"href": "https://mytfsserver/DefaultCollection/_apis/projectCollections/d81542e4-cdfa-4333-b082-1ae2d6c3ad16"
},
"web": {
"href": "https://mytfsserver/DefaultCollection"
}
}
}
还有一些示例 C# 代码的链接。
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
namespace Microsoft.TeamServices.Samples.Client.ProjectsAndTeams
{
[ClientSample(CoreConstants.AreaName, CoreConstants.ProjectCollectionsResource)]
public class ProjectCollectionsSample : ClientSample
{
[ClientSampleMethod]
public IEnumerable<TeamProjectCollectionReference> ListProjectCollections()
{
VssConnection connection = Context.Connection;
ProjectCollectionHttpClient projectCollectionClient = connection.GetClient<ProjectCollectionHttpClient>();
IEnumerable<TeamProjectCollectionReference> projectCollections = projectCollectionClient.GetProjectCollections().Result;
foreach(var collection in projectCollections)
{
Console.WriteLine(collection.Name);
}
return projectCollections;
}
}
}
推荐阅读
- python - 为什么木星中一个值的输出有时是正确的,有时不是?
- unit-testing - spark 单元测试框架示例 COM.holdenkarau 以外的示例
- file - Unix awk 将变量作为文件名传递
- java - 绑定的 jar 离开启动器图标
- java - JAX-RS WADL 不匹配命名空间的前缀
- python - pyrouge:__init__() 得到了一个意外的关键字参数“n_words”
- javascript - 为什么“0 && true”在 javascript 中返回 0 而不是布尔值?
- firebase - Xamarin Firebase iOS Analytics 抛出 AOT MTOUCH ERROR MT3001 - Firebase.Analytics.dll
- checkbox - 如何在 Flutter 中创建圆形 CheckBox?或者改变 CheckBox 的样式,比如 Flutter 中选中的图片?
- java - 什么时候可以使用枚举的 name()