Deploy Web API to Azure API Management via Azure Devops CI/CD pipelines — Part 1

Marvin Heng
2 min readMar 7, 2022

This series of tutorial, which consists of 3 following parts, will be demonstrating on how to deploy ASP.NET Web API endpoints at the same time update definition in Azure API Management through Azure Devops CI/CD pipelines:

Part 1: Configuring Web API project

Part 2: Create an instance of API Management and Web API on Azure

Part 3 : Create CI/CD Pipeline on Devops

Prerequisites:

  1. Microsoft Azure account
  2. Visual Studio 2022 (In this tutorial, we are using .NET6 project)

Sample Code is available at GitHub: https://github.com/hmheng/apimdemo

Part 1: Configuring Web API project

Step 1 — Create Web API

Step 2 — Build and run it to make sure it is working

Step 3 — Go to Web API project folder, open powershell/terminal and enter the following commands:

dotnet new tool-manifest

This would generate dotnet-tool.json manifest file.

dotnet tool install — version 6.2.3 Swashbuckle.AspNetCore.Cli

This would install the Swashbuckle.aspnetcore.cli to the dotnet tool.

Step 4 — Edit the .csproject file and add the following configuration line so swagger file would be generated.

<Target Name=”SwaggerToFile” AfterTargets=”AfterBuild” Condition=”’$(Configuration)’==’Release’”>
<Exec Command=”dotnet swagger tofile — output <preferred filename>.json &quot;$(TargetPath)&quot; &quot;<API name> &quot;” />
</Target>

Step 5— After adding the configuration, you should see refv1.json being generated.

Don’t forget to commit all the changes to Azure Devops.

Next: Part 2: Create an instance of API Management and Web API on Azure

--

--

Marvin Heng

An tech specialist also a Microsoft MVP who loves to try new things and publishes sample codes on github.