Skip to content

BerserkerDotNet/VSTS.Net

Repository files navigation

VSTS.Net

.Net client for Azure DevOps Services (Visual Studio Team Services) API

Build status

Nuget

Nuget

Api documentation

Usage

Console app

var query = @"SELECT [System.Id] FROM WorkItems 
        WHERE [System.WorkItemType] IN ('Bug', 'Task') AND [System.AssignedTo] Ever '[email protected]' AND System.ChangedDate >= '01/01/2018'";

var urlBuilderFactory = new OnlineUrlBuilderFactory("foo");
var client = VstsClient.Get(urlBuilderFactory, accessToken: "secure token");
var items = await client.GetWorkItemsAsync(new WorkItemsQuery(query));

For OnPrem (TFS) versions use OnPremUrlBuilderFactory instead of OnlineUrlBuilderFactory

Asp.Net Core

In the Startup.cs add VstsNet to the services collection

services.AddAzureDevOpsServices(instanceName: "foo", accessToken: "secure token");

or if you have OnPrem (TFS) version:

services.AddAzureDevOpsServices(new Uri("https://foo.mydomain.com"), accessToken: "secure token");

To use Azure DevOps Services style url:

services.AddAzureDevOpsServices(new Uri("https://dev.azure.com/{organization}"), accessToken: "secure token");

Now you can consume Vsts client through DI:

private readonly IVstsClient client;

public HomeController(IVstsClient client)
{
	this.client = client;
}

public async Task<IActionResult> Index()
{
    var prs = await client.GetPullRequestsAsync("MyProject", "MyRepository", new PullRequestQuery { CreatedAfter = DateTime.Now.AddDays(-5) });
}