зеркало из
1
0
Форкнуть 0
.NET/C# samples for integrating with Azure DevOps Services and Azure DevOps Server
Перейти к файлу
Bo d7c8d8eeb4 Remove some change 2019-01-30 14:44:53 -08:00
.github Add PR template 2018-08-20 09:19:26 -04:00
ClientLibrary Remove some change 2019-01-30 14:44:53 -08:00
ServiceHooks/Utilities/Permissions Refactor repo to open up room for quickstarts and other samples 2017-07-11 08:40:25 -04:00
.gitignore exclude .vs 2017-06-27 08:42:28 -04:00
README.md updated readme.md (#188) 2018-11-08 06:18:30 -08:00
azure-pipelines.yml Set up CI with Azure Pipelines 2018-10-16 17:26:04 +05:30
issue_template.md Create issue_template.md 2018-02-08 15:30:40 -05:00
license.md Snapshot of refactoring 2017-03-29 17:01:40 -04:00

README.md

.NET samples for Azure DevOps

buildstatus

This repository contains C# samples that show how to integrate with Azure DevOps and Team Foundation Server using our public client libraries, service hooks, and more.

Explore the samples

Take a minute to explore the repo. It contains short snippets as well as longer examples that demonstrate how to integrate with Azure DevOps and Team Foundation Server

  • Snippets: short reusable code blocks demonstrating how to call specific APIs.
  • Quickstarts: self-contained programs demonstrating a specific scenario, typically by calling multiple APIs.

About the official client libraries

For .NET developers, the primary (and highly recommended) way to integrate with Azure DevOps and Team Foundation Server is via our public .NET client libraries available on Nuget. Microsoft.TeamFoundationServer.Client is the most popular Nuget package and contains clients for interacting with work item tracking, Git, version control, build, release management and other services.

See the Azure DevOps client library documentation for more details.

Sample console program

Simple console program that connects to Azure DevOps using a personal access token and displays the field values of a work item.

using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 3)
            {
                Uri accountUri = new Uri(args[0]);     // Account URL, for example: https://fabrikam.visualstudio.com                
                String personalAccessToken = args[1];  // See https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/pats?view=vsts              
                int workItemId = int.Parse(args[2]);   // ID of a work item, for example: 12

                // Create a connection to the account
                VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));
                
                // Get an instance of the work item tracking client
                WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();

                try
                {
                    // Get the specified work item
                    WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result;

                    // Output the work item's field values
                    foreach (var field in workitem.Fields)
                    {
                        Console.WriteLine("  {0}: {1}", field.Key, field.Value);
                    }
                }
                catch (AggregateException aex)
                {
                    VssServiceException vssex = aex.InnerException as VssServiceException;
                    if (vssex != null)
                    {
                        Console.WriteLine(vssex.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine("Usage: ConsoleApp {accountUri} {personalAccessToken} {workItemId}");
            }
        }
    }
}

Request other samples

Not finding a sample that demonstrates something you are trying to do? Let us know by opening an issue.