c# – 如何从TFS获取构建定义?

前端之家收集整理的这篇文章主要介绍了c# – 如何从TFS获取构建定义?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用给定 collection-guidproject-name的TFS-API获取构建定义

有关详细信息,请参阅here.这是TFS最好的资源之一.

解决方法

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;
}
原文链接:https://www.f2er.com/csharp/91703.html

猜你在找的C#相关文章