本文介绍了如何使用microsoft teamfoundation build2 webapi 14.0.0.0版编辑现有的构建定义。 (VS2015)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,我浪费了大量时间试图弄清楚如何通过web api获取构建定义但没有成功。希望你们可以帮助我。

Greetings, I've wasted a good amount of time trying to figure out how to get the build definition through the web api with no success. Hopefully you guys can help me out with that.

如标题中所述,我使用microsoft teamfoundation build2 webapi 14.0.0.0版(带有视觉工作室2015)。

As mentioned in the title, I use microsoft teamfoundation build2 webapi version 14.0.0.0 (with visual studio 2015).

我以这种方式获得httpClient:

I get the httpClient this way :

var httpClient = tpc.GetClient<Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient>();

tpc是teamProjectCollection。

tpc being the teamProjectCollection.

我看到httpClient有一个名为GetDefinitionAsync的方法,它返回一个DefinitionReference对象。但是我不想要那个对象,我想要BuildDefinition一个(它扩展了DefinitionReference)。我尝试了向下转换,但正如预期的那样,
缺少一些信息。 

I saw the the httpClient has a method called GetDefinitionAsync which returns me a DefinitionReference Object. However I don't want that object, I want the BuildDefinition one (which extends of DefinitionReference). I tried downcasting however, as expected, some info is missing. 

我正在尝试将BuildDefinition与Build相关联,以编辑BuildDefinition.Properties dictionnary添加我在Web应用程序上定义的一些额外属性。你有任何想法吗?也许你们可以指导我获得与Build相关的BuildDefinition

I'm trying to get the BuildDefinition associated with a Build to edit the BuildDefinition.Properties dictionnary to add some extra properties I define on a web application. Do you have any idea to do so? Perhaps you guys could guide me into getting the BuildDefinition associated with a Build?

提前致谢! 

Thanks in advance! 

推荐答案

感谢您在此发帖。

根据我机器上的测试,我可以使用以下代码来获取所有构建定义中的所有构建:

According to the test in my machine, I could use the following code to get all the builds in all build definitions:

using System;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.Client;
namespace TfsApplication
{
    class Program
    {
        static void Main(String[] args)
        {
            var tfsUrl = "http://XXXX:8080/tfs/DefaultCollection";
            var buildClient = new BuildHttpClient(new Uri(tfsUrl), new VssAadCredential());
            var definitions = buildClient.GetDefinitionsAsync(project: "TestGaoScrum1");
            var builds = buildClient.GetBuildsAsync("TestGaoScrum1");

            foreach (var build in builds.Result)
            {
                Console.WriteLine(String.Format("{0} - {1} - {2} - {3}", build.Definition.Name, build.Id.ToString(), build.Status.ToString(), build.StartTime.ToString()));
            }
        }
    }
}

您可以检查builds.Result中的数据是否符合您的要求。

You could check if the data in builds.Result could meet your requirement.

最好的问候

Limitxiao Gao

Limitxiao Gao


这篇关于如何使用microsoft teamfoundation build2 webapi 14.0.0.0版编辑现有的构建定义。 (VS2015)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:13