---
title: "Configuring a Build Pipeline on Azure DevOps for an ASP.NET Core API"
description: "Configure a build pipeline on Azure DevOps that builds the project, ensures everything is compiling, and checks to see that tests are passing."
url: "https://blog.sentry.io/configuring-build-pipeline-azure-devops-asp-dotnet-core-api/"
canonical_url: "https://blog.sentry.io/configuring-build-pipeline-azure-devops-asp-dotnet-core-api/"
authors: ["Bruno Garcia"]
published: "2018-10-30"
category: "Product Updates"
---

# Configuring a Build Pipeline on Azure DevOps for an ASP.NET Core API

[_Joao Grassi_](https://blog.joaograssi.com/)\_ — a .NET developer, front-end hobbyist, and friend of Sentry — likes .NET very much and recently tried to bring a friend to the “dark side” of .NET development. To win a point, he decided to create a small sample project using Azure DevOps.\_

_As he started, he struggled to find helpful information in the documentation (like how to control the artifact name). As he finished the project, he wondered: Wouldn’t be nice to have this somewhere to save the hassle of Googling everything again?_

There’s no doubt that Cloud development is becoming more and more popular, and for many, the de facto way of building, deploying, and hosting apps on the web. But many of us still work on our daily jobs in a cloud-less environment due to reasons that are not relevant to this post.

There’s really no excuse when it comes to avoiding cloud development and taking advantage of all the good things you can get from it. One specific benefit is the ability to configure a build pipeline that builds the project, ensures everything is compiling, and checks to see that tests are passing. Build pipelines also produce Artifacts, or .zip files containing the code for your application, that allow you to publish your app on Azure or other cloud services.

## What we are going to do

In this post, I want to show you how to:

1.  Create an App Service on Linux on Azure.
2.  Set up a build pipeline on Azure DevOps (previously known as VSTS).
3.  Integrate Azure DevOps with Sentry.

## Some requirements

To avoid making this post too long, I’ll assume that you already have the following set up:

-   An account on Azure DevOps within an organization: [Just follow the steps here](https://visualstudio.microsoft.com/team-services/).
-   A git repo on Azure DevOps for your project: [here](https://docs.microsoft.com/en-us/vsts/repos/git/share-your-code-in-git-vs-2017?view=vsts) and [here](https://docs.microsoft.com/en-us/vsts/repos/git/create-new-repo?view=vsts).
-   The actual code — An ASP.NET Core API up and running (the simplest initial template (ValuesController), either via VS or command line).

At the end, you should have your git repo configured both locally and on Azure DevOps so you’re able to push/pull stuff. The “Repos” menu on Azure DevOps Looks like this:

![Git Repo Azure DevOps](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-0.B4fei7RS.png&w=1920&q=100)

## Creating the App Service on Azure

I’m also not going into too much details on how to create the App Service on Azure mainly because it was already [explained better before](https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-dotnet), but I do want to show you via the Azure Portal briefly. So let’s go:

1.  Log into your Azure portal (after creating your free account).
2.  Go to: _App Services → Add (+) → Web App → Create_

![Adding a new Web Application via Azure DevOps App Services](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-1.IPoYeq8W.png&w=1920&q=100)

1.  Fill in all the fields, as seen here:

![Creating the App Service on Linux](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-2.elEg2oZe.png&w=1080&q=100)

1.  Hit Create!

## Creating the build on Azure DevOps

Now that you have your git repo and your App Service created, it’s time to configure the build pipeline on Azure DevOps. It’s very easy and well integrated with ASP.NET Core, so we’ll use most of the pre-defined values:

1.  Navigate to: _Pipelines → + New → New build pipeline_.
2.  On the next page you need to select the source for the build, which in our case is Azure Repos Git. But as you can see you can connect to other Git providers like GitHub. Select your project and repository (it’s probably already pre-selected) and hit _Continue_.

![Creating your first build on Azure DevOps](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-3.kjar_ZgQ.png&w=1920&q=100)

1.  On the “Select a template” page, select _ASP.NET Core_ and hit _Apply_ (you can also search for it).
2.  The next page is where we’ll configure the build steps. Since we selected the ASP.NET Core template, Azure DevOps already gives us a set of pre-defined steps. I experimented with those a bit and came up with my own changes. I’ll explain each step now:

### Pipeline - Build pipeline

The first “box” is the one at the top of everything: _Pipeline_. There, you can set up the name of the build pipeline, on which agent it runs and the projects to build/restore. Fill in the Build name and Agent “Hosted VS2017”. Leave the rest as it is, we will change them later:

![Configuring initial build pipeline](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-4.JJe59BOh.png&w=1920&q=100)

### Restore

We don’t have to do a restore since .NET Core 2.0, but, in CI builds like this, it’s nice to have it separated because we can measure how much time each step took.

Make sure to select the .NET Core version to 2.\* The only thing we are going to change here is the Path to project(s). By default it tries to restore all the projects. In our simple API, we just need to restore the Api project.

1.  In the _Path to project(s)_ field, click on the _link_ icon next to it and then on _Unlink_. This will enable us to change the field.
2.  Change it to the path of your main API `.csproj` file. In my case it’s: `**/StarWars.Api.csproj`

Now it does a restore for the API project, and if the API has dependencies to other projects in the solution, it will restore for those as well.

### Build

In the _Build_ step we will change 3 things: the _Path to project(s)_, the _Arguments_ and the _Working Directory_.

1.  Click again in the _link_ icon next to _Path to project(s)_ and point it to the `.csproj`of your API again like in the restore step.
2.  In the _Arguments_ step add a `--no-restore` flag to avoid `dotnet build` doing a restore again: `--configuration $(BuildConfiguration) --no-restore`
3.  Expand the _Advanced_ menu and add the folder of your API project to the _Working Directory_. In my case, this: `src/StarWars.Api`

I always use this format for my projects (and I believe most projects out there also use it):

![My preference for project structure](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-5.VKYT4c1g.png&w=640&q=100)

You are not required to have this structure, but I think it works nicely and it’s well organized. For instance, I like to put all my test projects under a test folder in the same hierarchy as the src folder.

### Test

In the _Test_ step, I specify the projects I want to test. A big solution often has multiple projects, and you probably also have separate builds for each of them. In this case, it makes more sense to specify each test project to run.

### Publish

The _Publish_ step was where I got caught up the first time I tried to set up my build pipeline. You can pretty much use the defaults, and it will work just fine. The problem is: it publishes the artifacts with very weird names. For example:

![Azure DevOps bad artifact name](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-6.D85BFGWn.png&w=640&q=100)

I couldn’t figure out a better artifact name using the default options. Artifact names should be meaningful and include information like the build number. I eventually used these steps to change the artifact name:

1.  Uncheck the _Publish Web Projects_ checkbox and add again the path to the API project: `**/StarWars.Api.csproj`
2.  In the _Arguments_ paste this: `-c $(BuildConfiguration) -o $(Build.StagingDirectory)/ci-build --no-build`

The `-c` command will tell Azure DevOps to use the `BuildConfiguration` variable. By default the variable is set to `release`, but you can change it in _Variables_ tab on this page.

The `-o` argument specifies the location of the publish output. In my example, I specified it to publish into the pre-defined `Build.StagingDirectory` available in Azure DevOps plus into the `ci-build` folder. If you don’t specify the `ci-build` folder, it will create a folder for it.

And, of course since we have built the project already, no need to do it again. So, skip the `--no-build`.

1.  I also unchecked the _Zip Published Projects_ and _Add project name to publish path_. We’ll create our own zip in the next step.
2.  Expand again the _Advanced_ menu and set the _Working folder_ again as we did in the _Build_ step.

These steps should result in something like this:

![Azure DevOps Publish step](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-7.CMnw-X7G.png&w=1080&q=100)

### Archive the publish output

Now that we have the outputs from our `dotnet publish` command, we need to archive it.

1.  Click on the _\+ button_ near _Phase 1_.
2.  Select the _Archive Files_ option. You can search for it if not visible.
3.  Choose a name for the step, e.g., _Archive Publish Output_.
4.  In the _Root folder_ or _file to archive_ add the path to the `publish` output files configured before: `$(Build.StagingDirectory)/ci-build`
5.  I don’t want to prepend the root folder name in the zip, since I’d like my files to be at the root. So I unchecked the _Prepend root folder name to archive paths_ checkbox.
6.  In the _Archive file_ to create is where we configure the name of the zip artifact. I changed mine to: `$(Build.ArtifactStagingDirectory)/starwars-api.$(Build.BuildNumber).zip`. Make sure also to mark the _Replace existing archive_ just in case.

This step grabs the files produced from the `publish` step available in `$(Build.StagingDirectory)/ci-build` and zips them with a name consisted of `starwars-api.buildnumber.zip`. I used the `Build.BuildNumber` variable exposed by Azure DevOps to construct that name. Note that I also hard-coded the `starwars-api` part, but you can also set a variable for that, or use one of the [many predefined ones](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables?view=vsts), like the build name for instance.

The archive step should look like this:

![Azure DevOps Archive step](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-8.D7VrgvyG.png&w=640&q=100)

### Publish Artifact

In this step we are just picking up the .zip file, and moving it to the appropriate folder in Azure DevOps. Since we changed the defaults, we need to change some fields here as well to match our new artifact name/path:

1.  Change the _Path to publish_ to: `$(Build.ArtifactStagingDirectory)/starwars-api.$(Build.BuildNumber).zip`. This will publish our zip to that location.
2.  In the _Artifact_ name field add again the artifact name we created: `starwars-api.$(Build.BuildNumber)`
3.  Leave the rest with default values.

That’s it for the build part! Now you can go to _Pipelines → Builds → Queue_, wait for it to finish and you should have a nice artifact.

![Azure DevOps artifact name](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-9.Cu2XPtOF.png&w=1080&q=100)

And if you click on it, you can download it to your machine:

![Downloading Azure DevOps artifact](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-10.DSjjlosk.png&w=828&q=100)

## Integrating Sentry and Azure DevOps

Now that your build pipeline is set up on Azure DevOps, you can [integrate with Sentry](https://docs.sentry.io/integrations/source-code-mgmt/azure-devops/) unlock enhanced release tracking, informative deploy emails, and assignee suggestions for new errors.

1.  In Sentry, navigate to _Organization Settings → Integrations_. (Note: only users with Owner and Manager permissions will have access to this page.)

![Sentry integrations](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-11.ClMiLfzL.png&w=1200&q=100)

1.  If you have the legacy VSTS integration installed, you’ll see a button next to Azure DevOps that says _Upgrade_. If you do not have the legacy VSTS integration installed, you’ll see a button that says _Install_. Click this button.
2.  In the resulting modal, click _Add Installation_.
3.  An Azure DevOps install window should pop up. Select the Azure DevOps account you’d like to link with Sentry, and press _Submit_.

![Sentry Azure DevOps configuration](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-12.DMMqGEj6.png&w=640&q=100)

Read more about the features of this integration [here](https://blog.sentry.io/sentry-azure-devops-integration-update/), and learn how to configure those features [here](https://docs.sentry.io/integrations/source-code-mgmt/azure-devops/).

You can also check out Joao’s original post, ping him with your questions, and read about his other adventures in .NET on [his blog](https://blog.joaograssi.com/).
