What object returns from TFS2015 RestAPI

2020-05-08 07:21发布

问题:

I'm using TFS 2015 rest api in order to retrieve build definitions and builds details using those calls:

definitions: http:///tfs/DefaultCollection//_apis/build/definitions?name=ampm&api-version=2.0

builds: http:///tfs/DefaultCollection//_apis/build/builds?definition=DigitalVault_Automation&statusFilter=completed&$top=10&api-version=2.0

I get a rich JSON and I wonder if there is a standard Class that I can deserialize those JSONs to.

Couldn't find any reference in Microsoft's guide though.

回答1:

You could use install this Nuget package for your project and in the package. The assemblies in this package has already help you transfer the json data to the corresponding object. For example, to get something about build, you could use the Microsoft.TeamFoundation.Build.WebApi assembly. To get a build definition:

var u = new Uri("http://serverName:8080/tfs/MyCollection/");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("userName", "password", "domain")));
var connection = new VssConnection(u, c);
var buildServer = connection.GetClient<BuildHttpClient>();            
BuildDefinition builddef = buildServer.GetDefinitionAsync("AgileMttGreen",10).Result;
Console.WriteLine(builddef.Name);


回答2:

I use Json.NET to manipulate JSON data. You can find plenty of examples in this library web site.



标签: rest tfs