.NET client libraries

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Client libraries are available for .NET developers who build Windows apps and services that integrate with Azure DevOps. Client libraries integrate with work item tracking, version control, build, and other services. These packages make it easy to acquire and redistribute the libraries needed by your app or service.

Tip

Find the corresponding .NET client class and API method, using .NET Client Library Samples and Azure DevOps API Reference.

Dependency diagram

Dependency diagram shows the relationship between Services.Client, Services.InteractiveClient, and TeamFoundationServer.Client.

Features of .NET Client Libraries

The .NET client libraries for Azure DevOps offer several key features that make it easy to integrate with services in Azure DevOps from your Windows applications and services:

  • Downloadable from NuGet.org: Easily import the libraries into your Visual Studio projects by downloading them from NuGet.org.
  • Licensed for redistribution: The libraries are licensed for redistribution in your apps and services. You can view the license for more details.
  • Access to APIs: Gain access to both traditional client object model APIs and REST APIs to interact with Azure DevOps programmatically.

Package and Azure DevOps version-mapping table

The following table maps the package versions of the .NET client libraries to the corresponding versions of Azure DevOps Server. Use this table to determine which package version corresponds to your Azure DevOps version.

Package version Azure DevOps version
16.205.x versions >= Azure DevOps Server 2022
16.170.x versions >= Azure DevOps Server 2020
16.153.x versions >= Azure DevOps Server 2019 Update 1
16.143.x versions >= Azure DevOps Server 2019

For the latest preview versions, see the NuGet packages gallery.

REST packages

The following table lists the .NET client libraries available for accessing various services via public REST APIs. These packages can be downloaded from NuGet.org and provide the necessary binaries to integrate with Azure DevOps.

Packages and description Binaries
Microsoft.VisualStudio.Services.Client
Provides access to shared platform services via public REST APIs, like organization, profile, identity, security, and more.
Microsoft.VisualStudio.Services.WebApi.dll, Microsoft.VisualStudio.Services.Common.dll, Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundationServer.Client
Provides access to version control, work item tracking, build, and more via public REST APIs.
Microsoft.TeamFoundation.Build2.WebApi.dll, Microsoft.TeamFoundation.Core.WebApi.dll, Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll, Microsoft.TeamFoundation.SourceControl.WebApi.dll, Microsoft.TeamFoundation.TestManagement.WebApi.dll, and so on.
Microsoft.VisualStudio.Services.InteractiveClient
Supports applications that require interactive sign-in by a user.
Microsoft.VisualStudio.Services.Client.Interactive.dll
Microsoft.VisualStudio.Services.Release.Client
Provides access to the Release Service via public REST APIs.
Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll
Microsoft.TeamFoundation.DistributedTask.Common.Contracts
Provides the models used to access the Distributed Task Service via public REST APIs.
Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll
Microsoft.TeamFoundation.DistributedTask.WebApi
Provides access to the Distributed Task Service via public REST APIs.
Microsoft.TeamFoundation.DistributedTask.WebApi.dll
Microsoft.VisualStudio.Services.ServiceHooks.WebApi
Provides access to the Service Hooks Service via public REST APIs.
Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll
Microsoft.VisualStudio.Services.Gallery.WebApi
Provides access to the Gallery Service via public REST APIs.
Microsoft.VisualStudio.Services.Gallery.WebApi.dll
Microsoft.VisualStudio.Services.Notifications.WebApi
Provides access to the Notifications Service via public REST APIs.
Microsoft.VisualStudio.Services.Notifications.WebApi.dll
Microsoft.VisualStudio.Services.ExtensionManagement.WebApi
Provides access to the Extension Management Service via public REST APIs.
Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll
Microsoft.VisualStudio.Services.MemberEntitlementManagement.WebApi
Provides access to the Member Entitlement Management Service via public REST APIs.
Microsoft.VisualStudio.Services.MemberEntitlementManagement.WebApi.dll
Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi
Provides access to the Service Endpoints via public REST APIs.
Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.dll
Microsoft.VisualStudio.Services.Search.Client
Provides access to the Search Service via public REST APIs.
Microsoft.VisualStudio.Services.Search.Shared.WebApi.dll, Microsoft.VisualStudio.Services.Search.WebApi.dll
Microsoft.TeamFoundation.PublishTestResults
This task can be used to publish test results and upload test attachments on Azure DevOps. The following results formats are supported with this package: 1. JUnit - publish tests from JUnit projects, 2. NUnit - publish tests from NUnit projects, 3. VSTest - publish tests from Visual Studio projects, 4. Xunit - publish tests from Xunit projects.
Microsoft.TeamFoundation.TestClient.PublishTestResults.dll
Microsoft.VisualStudio.Services.Audit.WebApi
Provides access to the Audit Service via public REST APIs.
Microsoft.VisualStudio.Services.Audit.WebApi.dll
Microsoft.Azure.Pipelines.Policy.Client
Provides access to the pipeline approvals, checks, and authorization via public REST APIs.
Microsoft.Azure.Pipelines.Policy.Client.dll

Tip

If you have an existing Windows application or service that uses the TFS Client Object Model, use Microsoft.TeamFoundationServer.ExtendedClient. This package provides access to the older SOAP-based APIs, which are necessary for certain functionalities not available in the newer REST APIs. However, this package doesn't support .NET Standard and is intended for use only when the REST APIs don't offer the required functionality.

Soap package

The following table lists the .NET client libraries available for accessing various services via SOAP APIs. These packages can be downloaded from NuGet.org and provide the necessary binaries to integrate with Azure DevOps. Only use these packages when the REST APIs don't offer the functionality you need, for example, creating workspaces in TFVC.

Package and description Binaries
Microsoft.TeamFoundationServer.ExtendedClient
Work with and manage version control, work items, build, and other resources from your client application. This package doesn't support Net Standard Client OM. Only use this package when our REST APIs don't offer the functionality you need (for example, creating workspaces in TFVC).
Microsoft.TeamFoundation.Build.Client.dll, Microsoft.TeamFoundation.DeleteTeamProject.dll, Microsoft.TeamFoundation.Diff.dll, Microsoft.TeamFoundation.Git.Client.dll, Microsoft.TeamFoundation.SharePointReporting.Integration.dll, and so on.

Install

Install from a NuGet package manager command prompt:

PM> Install-Package Microsoft.TeamFoundationServer.ExtendedClient

Connect

To create an authenticated connection to Azure DevOps, get an HttpClient for the service you want to work with, and then call methods against that service.

See the following examples:

using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;

const String c_collectionUri = "https://dev.azure.com/fabrikam";
const String c_projectName = "MyGreatProject";
const String c_repoName = "MyRepo";

Uri orgUrl = new Uri(c_collectionUri);

// Connect to Azure DevOps Services
VssConnection connection = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, personalAccessToken));

// Get a GitHttpClient to talk to the Git endpoints
using (GitHttpClient gitClient = connection.GetClient<GitHttpClient>())
{
    // Get data about a specific repository
    var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).Result;
}

Authentication paths that produce an interactive dialog aren't available in the .NET Standard version of the .NET client libraries. When you're using the .NET Standard version, provide your credentials more explicitly to authenticate, like in the following example.

using System;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;

namespace ConsoleApp1
{
    class Program
    {
        const string collectionUri = "https://dev.azure.com/fabrikam";
        const string projectName = "MyGreatProject";
        const string repoName = "MyRepo";
        const string pat = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

        static void Main(string[] args)
        {
            var creds = new VssBasicCredential(string.Empty, pat);
            
            // Connect to Azure DevOps Services
            var connection = new VssConnection(new Uri(collectionUri), creds);
            
            // Get a GitHttpClient to talk to the Git endpoints
            using var gitClient = connection.GetClient<GitHttpClient>();
            
            // Get data about a specific repository
            var repo = gitClient.GetRepositoryAsync(projectName, repoName).Result;
        }
    }
}

For more authentication samples, see .NET Samples.

Reference

For more information and for up-to-date reference documentation, see the .NET API browser.

Samples

Check out samples on our .NET Samples Page or directly on our .NET GitHub Repo.

For more information on NuGet packages, see Microsoft.VisualStudio.Services.Client.

Known issues

Interactive authentication dialog doesn't appear when using the Azure DevOps OM in a Single Threaded Apartment (STA)

The interactive authentication dialog doesn't appear in cases where your code is running from a Single Threaded Apartment (STA). This issue can commonly occur from WPF applications. To work around this issue, you can change your initialization method to be async and request authentication as in the following example.

async void InitAzureDevOps()
{
    Uri _uri = new Uri("https://dev.azure.com/MyAccount/");

    var creds = new VssClientCredentials(new WindowsCredential(false),
                                         new VssFederatedCredential(false),
                                         CredentialPromptType.PromptIfNeeded);

    VssConnection vssConnection = new VssConnection(_uri, creds);
    CancellationTokenSource source = new CancellationTokenSource();
    CancellationToken token = source.Token;
    await vssConnection.ConnectAsync(token);

    ...

}

Using NetStandard 2.0 versions of the Azure DevOps OM

For version 16.143.1 of our NuGet packages, we support NetStandard 2.0. These packages correlate with Azure DevOps Server 2019 RTW and are fully compatible with Azure DevOps.

Microsoft.TeamFoundationServer.ExtendedClient package doesn't have NetStandard support

The Microsoft.TeamFoundationServer.ExtendedClient doesn't support a NetStandard compliant version.

Important

This package includes our older SOAP object model, which we replaced by our newer REST object model. We're no longer investing in the older SOAP object model, and have no plans to create a NetStandard version of it.