C# · 12月 23, 2021

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

如何使用给定 collection-guid和 project-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;}