Search code examples
c#azure-devopsrelease-management

Setting 'KeepForever' for a TFS Release


I use Microsoft.VisualStudio.Services.Release.Client to modify TFS Releases from C# Code. I use Version 16.143.2 of the ClientLibrary and TFS2017Update2. I just want to modify the KeepForever flag of a release, but it does not work. The updated release, that is returned by the method 'UpdateReleaseAsync' always has the 'old' value for KeepForever. This is my code:

    public void SetReleaseRetainIndefinitely(ReleaseHttpClient releaseClient, Release release, string tfsProjectName, bool retain)
    {
        release.KeepForever = retain;
        var task = releaseClient.UpdateReleaseAsync(release, tfsProjectName, release.Id);
        var updatedRelease = task.Result;
        if (updatedRelease.KeepForever == retain)
        {
            Console.WriteLine($"Set 'Retain Indefinitely' to {retain}");
        }
        else
        {
            Console.WriteLine($"Failed to set 'Retain Indefinitely' to {retain}");
        }
    }

Any hints what I am doing wrong?


Solution

  • You should use UpdateReleaseResourceAsync method with ReleaseUpdateMetadata instead