Search code examples
c#.netresttfstfs-2015

TFS client libraries don't return specific value


Why are some properties of the build defintions obtained through the TFS client libraries empty? For example, I want to get the retentionRules and daysToKeep properties of a certain build definition but the values returned are empty. When I enter the URL of the build defintion in the browser I get the JSON object with all the expected details.

public static void BuildDefinitionSample()
{
    VssConnection connection = new VssConnection(new Uri(collectionUri), new VssClientCredentials());

    var buildClient = connection.GetClient<BuildHttpClient>();
    var buildDefinitions = buildClient.GetDefinitionsAsync(project: projectName, name: "MyBuildDefinition").Result;

    var daysToKeep = buildDefinitions.FirstOrDefault().retentionRules.daysToKeep;
}

How can I get the daysToKeep property of a certain build defintion through the TFS client libraries?

Thank you


Solution

  • TFS Client libraries (SOAP API) use Legacy Client Object Model while WebApi libraries calls the New Rest API to achieve the functions.

    Client libraries are primarily there to supply backward compatibility with XAML builds. They cannot work well with the new vNext build system as they were written before their time.

    TFS are even using two different Build Retention Policy for XAML build and vNext build. You could not set "daysToKeep" for a XAML build. Details please refer my answer in this question.

    Xaml Build Retention Policies

    So the REST API is the future way to follow and you need use it to get above values in your question.