We’re in the process of migrating a long-term project from our in-house build environment (Jenkins on Windows) to Azure DevOps. This is the first in a series of posts documenting our process.

This post is all about setting up the automated build process. Firstly, some particulars of our project:

  1. Project is in the DevOps git repository. It was moved from bitbucket.
  2. Solution contains three unit test projects, an ASP.NET application, console application, several assembly projects, all targeting .NET v4.7.
  3. Code is found under src/
  4. Unit Tests are using NUnit. This is important to know for later on in this post.
  5. Our Project tasks are currently controlled by rake tasks developed over the years (e.g. build, run unit tests, run selenium tests, create release artifacts). These will change depending on what Azure DevOps supports. Ideally we’d like to use as much of standard Azure DevOps tasks as possible.

Setting up Build Pipeline

I’m assuming you’ve created a project in Azure DevOps. Let’s get started by creating a Pipline file.

  1. In the Project area at https://{organisation}.visualstudio.com/{projectname}, click on “Pipelines”.
  2. Then select “New pipeline”.
  3. Now, select where you code is being retrieved from. We’re using “Azure Repos Git”.
  4. Now, select which repository in Azure DevOps (You may have multiple repositories in your Azure DevOps project).
  5. Configure your pipeline now. For this project we’re selecting “ASP.NET”.
  6. We’re presented with our azure-pipelines.yml file editor. This file includes tasks to build the project and run all tests in the solution.
  7. As we only have one solution for this project, I’m going to edit the “solution” property in the global variables to ‘src/TestProject.sln’ from ‘**/*.sln’. I like to be explicit here as sometimes we have different solutions for the same project. e.g. We might have a solution just to develop on the back-end in Visual Studio.
  8. Now select “Save and run”. Azure will prompt you whether you want to commit to master or commit to a new branch. I’ll select commit to master.
  9. Once Saved and committed, your build should now run.
  10. And now we wait for Azure to run the pipeline….
  11. And we’re done! However we have an issue with the VSTest task.

Fixing VSTest Task

  1. In VSTest task, we get a warning stating:
    ##[warning]Invalid results file. Make sure the result format of the file 'd:\a\1\s\TestResults\VssAdministrator_fv-az150_2019-04-02_11_26_15.trx' matches 'VSTest' test results format.
    Additionally in the console output of the VSTest task, it indicates that it couldn’t find any tests.
  2. After digging around, it turns out you need to have the nuget package “NUnit3TestAdapter” installed in your tests project. This allows the vstest.console app to find the tests in your tests project. We had never come across that previously as our Visual Studio installs always had the NUnit 3 Test Adapter extension installed and we had always controlled our automated tests via rake tasks using NUnit Console runner.
  3. After installing that, and committing the changes, we get all green!

So after all that, we now have the following:

  • Continuous building of our project
  • Continuous running of unit tests

What we need to do in the future is:

  • Deploy our project to a Windows Server
  • Run our end-to-end tests
  • Run integration tests
  • Generate a release artifact for a UAT and Production environment.