January 22, 2019

Build ASP.NET Framework Apps With Azure Pipelines

Thus, I thought it would be useful to share from the bits that I have found so far in working with Azure Pipelines YAML based build configurations.

Build ASP.NET Framework Apps With Azure Pipelines

There has been quite a bit of changes in the world of Azure DevOps at Microsoft, and with some of the announcements last year behind Azure Pipelines, I am digging deeper into the new YAML based build configuration in Azure Pipelines. However, I noticed that there hasn't been much yet written about using the new YAML based markup builds with Classic ASP.NET Framework applications. Thus, I thought it would be useful to share from the bits that I have found so far in working with Azure Pipelines YAML based build configurations.

Sample Project

Note that there is already some basic documentation on how to setup a YAML based build in Azure Pipelines using .NET Core here. However, I will show you a simple example for an ASP.NET MVC (.NET Framework 4.7.2) application, configured to build in Azure Pipelines utilizing the new YAML syntax.

The sample application is very straight forward, I simply created a new Visual Studio 2017 solution with a new ASP.NET application, targeting the .NET Framework 4.7.2, and a respective Test Project to match it. I have already uploaded the source code into Azure Repos, so it is ready to go for the next step:

YAML Build Sample VS Solution

Creating the YAML based build configuration

You can start a new build configuration from Azure DevOps by navigating to your Git repository in Azure Repos and then clicking on the Set up build magic button:

Set up build from Git repository

Next, you should see a New Pipeline setup wizard appear to guide you along the way. The first step will be the Connect step, in which you choose where your Git repository is hosted, in my case I am using a private repository in Azure Repos:

Once you have indicated where your code is hosted, you will then be asked to Select the Git repo for which you will be creating the YAML build  pipeline configuration file:

Select a repository for your YAML Build Configuration File

Next is the Configure step of the wizard, in which you will select a template for your YAML based build configuration file. This step is similar to using the Visual Designer to craft your build pipeline, in the sense that it offers a template to get you started. However, even though the template comes close to providing you with a basic starting point, there is one step that is missing from making it a complete starting point. Nevertheless, I will get to that shortly, for now just continue with the Configure step and select ASP.NET | Build and test ASP.NET projects.

Consequently, you will now be at the Create pipeline step where you can see the contents of the newly generated YAML configuration file displayed, with a default name of "azure-pipelines.yml" for the name of the file. At this point, you can peruse through the YAML contents and see exactly what the build will be doing. Click on the Save and run button and continue to the next step:

On this step, you should now see the Save and run modal side screen pop up next. There are a few important points that you should understand before clicking on the final Save and run button, so let's start from the top. Notice that if you proceed with saving, the wizard will commit the newly minted "azure-pipelines.yml" to the root of your Git repository ( note the './' in front of the file), as this is the default structure expected by Azure Pipelines when configured to utilize YAML based build configurations. Also, the two textboxes are simply the Git entries for commit comments, which will be entered directly into your default branch, that in my case with this very simple example is just 'master'. However, since most developers would be working in a team, I assume you would have a branching strategy that may include multiple branches, one of which will be set as the default branch. This is important because the wizard will always create your initial "azure-pipelines.yml" file in the branch you have have set as the default branch, just something to keep in mind.

Once you proceed with clicking on the Save and run button, your new "azure-pipelines.yml" is created and committed to your default branch and then the build will start:

First successful build

Once your build finishes and you see green checkmarks on the Summary page, you can rejoice...but don't count victory just yet. That is because, if you were to click on the Summary tab of the build page shown above, you will see that there are no build artifacts available. So, while the automated template that was generated by Azure Pipelines and placed in "azure-pipelines.yml" file is a good start, it is still missing one task to publish the artifacts:

Fortunately, another neat feature of Azure Pipelines is the ability to edit the "azure-pipelines.yml" file on the web editor. This is convenient when you are first building your YAML build configuration, and want to quickly edit and run your build until it is exactly how you want it. Therefore, to edit your YAML build configuration, you navigate to your pipeline and then click on the Edit button to update your build:

Edit YAML Build

Here you can add the missing task that will publish your build artifacts, that you can consequently use in a Release Pipeline:

The full content of the YAML build configuration file should be like so:

Now you can again, Save and run your update to the "azure-pipelines.yml" configuration file on your branch, and wait for the new build to take place:

And now you should be able to see the new published build artifacts from the Summary page:

Congratulations, now that your build is generating artifacts, and you can move on to creating a test Release. However, that would be a topic for a future post. :)

Wrap Up

Azure Pipelines feature for supporting YAML based build configurations allows you to version your build pipeline in your own Git repository, while also providing an accessible way to update your builds right from your browser. If you are interested in knowing more about YAML usage in Azure Pipelines, check out the official docs for the YAML schema reference, dive in and have fun.