如何使用collection-guid和project-name
的TFS-API获取构建定义有关详细信息,请参阅here。这是关于TFS的最佳资源之一。
答案 0 :(得分:9)
private TfsConfigurationServer configurationServer;
configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(uri);
public IList<KeyValuePair<string, Uri>> GetBuildDefinitionListFromProject(Guid collectionId, string projectName)
{
List<IBuildDefinition> buildDefinitionList = null;
List<KeyValuePair<string, Uri>> buildDefinitionInfoList = null;
try
{
buildDefinitionInfoList = new List<KeyValuePair<string, Uri>>();
TfsTeamProjectCollection tfsProjectCollection =
configurationServer.GetTeamProjectCollection(collectionId);
tfsProjectCollection.Authenticate();
var buildServer = (IBuildServer)tfsProjectCollection.GetService(typeof(IBuildServer));
buildDefinitionList = new List<IBuildDefinition>(buildServer.QueryBuildDefinitions(projectName));
}
catch (Exception e)
{
ApplicationLogger.Log(e);
}
if (buildDefinitionList != null && buildDefinitionList.Count > 0)
{
foreach (IBuildDefinition builddef in buildDefinitionList)
{
buildDefinitionInfoList.Add(new KeyValuePair<string, Uri>(builddef.Name, builddef.Uri));
}
}
return buildDefinitionInfoList;
}