如何使用 Azure DevOps Services .NET SDK 获取所有项目迭代的列表?

How do you get a list of all project iterations using the Azure DevOps Services .NET SDK?

我想使用 .NET API 获取 Azure DevOps 存储库中给定项目的所有迭代列表。

有没有例子说明如何做到这一点?当前文档 (https://docs.microsoft.com/en-us/dotnet/api/microsoft.teamfoundation.work.webapi.workhttpclientbase.getteamiterationsasync?view=azure-devops-dotnet) 非常薄。

下面是一个如何实现这一点的工作示例。

您需要参考 Microsoft.TeamFoundation.Work.WebApi.

public async Task<List<TeamSettingsIteration>> GetProjectIterations(string serverUrl, string projectName)
{
    var uri = new Uri(serverUrl);
    var creds = new VssClientCredentials(new WindowsCredential(true), new VssFederatedCredential(true), CredentialPromptType.PromptIfNeeded);

    var azureDevopsConnection = new VssConnection(uri, creds);
    await azureDevopsConnection.ConnectAsync();

    WorkHttpClient azureDevOpsWorkHttpClient = azureDevopsConnection.GetClient<WorkHttpClient>();
    TeamContext teamContext = new TeamContext(projectName);

    List<TeamSettingsIteration> results=  await azureDevOpsWorkHttpClient.GetTeamIterationsAsync(teamContext);
    return results;
}