问题
I'm using this piece of code to determine the build definition details of a specific build:
TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
IBuildServer buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer));
IBuildDetail bd = buildServer.GetBuild(buildUri);
string a = bd.BuildDefinition.Name;
If the tfsUri and buildUri are pointing to a TFS2013 server and a TFS2013 build then the code is ok but if I change to TFS2015 server + build (vNext build) then the bd.BuildDefinition object becomes null.
How can I get the build details (build definition) of a vNext build using C# TFS API?
回答1:
I'm guessing that the TFS API you're using doesn't support Build vNext, you are probably going to have to try using the REST API.
You can use this to get the Build Definitions:
https://{your-project}.visualstudio.com/defaultcollection/taeguk/_apis/build/definitions?api-version=2.0
The once you have the "ID" you can use this call:
https://{your-project}.visualstudio.com/defaultcollection/taeguk/_apis/build/builds?api-version=2.0&definitions={id}
I'm basing this on what I've found on the Visual Studio Team Services REST API docs.
回答2:
Your question is very similar to this post here which I have answered. However, since you interest is in the build definition rather than the individual build, the code would need an alteration as such:
var definitions = buildClient.GetDefinitionsAsync(project: "<projectname>");
foreach (var definition in definitions.Result)
{
Console.WriteLine(definition.Name);
}
来源:https://stackoverflow.com/questions/32353000/builddefinition-null