GithubHelp home page GithubHelp logo

test-mass-forker-org-1 / azure-devops-dotnet-samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/azure-devops-dotnet-samples

0.0 0.0 0.0 1.4 MB

.NET/C# samples for integrating with Azure DevOps Services and Azure DevOps Server

Home Page: https://docs.microsoft.com/azure/devops/integrate

License: MIT License

C# 100.00%

azure-devops-dotnet-samples's Introduction

.NET samples for Azure DevOps

Build Status

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

Explore the samples

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

In the ClientLibrary folder, you'll find the following:

  • Samples: 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 Services and Azure DevOps 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 System;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;

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

                // Create a connection
                VssConnection connection = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, personalAccessToken));

                // Show details a work item
                ShowWorkItemDetails(connection, workItemId).Wait();
            }
            else
            {
                Console.WriteLine("Usage: ConsoleApp {orgUrl} {personalAccessToken} {workItemId}");
            }

        }

        static private async Task ShowWorkItemDetails(VssConnection connection, int workItemId)
        {
            // Get an instance of the work item tracking client
            WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();

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

                // 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);
                }
            }
        }
    }
}

Request other samples

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

azure-devops-dotnet-samples's People

Contributors

danhellem avatar willsmythe avatar vtbassmatt avatar vithati avatar bansalaseem avatar niadak avatar pranavgk avatar shayki5 avatar viradhamms avatar shpraka avatar chandan-anjani avatar shadyysf avatar hostr avatar olicea avatar nschonni avatar nenoloje avatar msftgits avatar mmanela avatar dorchuck avatar giridharannarayanan avatar adriennetacke avatar abdulsametileri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.