My current client, just started to use .NET core as their main development platform. I felt this is the right time to revisit the build steps and document them. So in this blog post we will see how easy it us to build and publish a .NET Core app within VSTS.

For sample, we have two .NET core web applications, one hosting an Angular application and another hosting an Identity Server.

  • First step we restore all the npm packages required for Angular application. For this we add npm task from the tasks library and run the command install

Npm

We set the working folder because our package.json is nested in a folder within the repository.

  • Our application is based on .NET Core SDK 2.1.300 and because we are running this build on a self hosted agent, we want to make sure the agent has .NET core 2.1.300 SDK is installed. To do that, we add .NET Core Tool Installer task to our build definition and install the required SDK.

Dotnet Core Tool Installer

  • We need to tell this task the version of .NET Core SDK we need. We do that by specifying the correct version number in the version field.

Dotnet Core Install Sdk

Please see the version number of SDK (or runtime) should exactly match as in the document here

  • Next we need to build the application. We add a .NET core task and select build option from the command dropdown. We are looking for all *.csproj files.

Dotnet Core Build

Note that, starting .NET Core 2.0, the application dependencies are automatically restored by commands dotnet build and dotnet publish. You no longer required to run dotnet restore command.

  • Next we need to execute our unit tests. To do that we again add dotnet core task and this time select test command. We are scanning tests in *.UnitTests.csproj projects. Make sure you check Publish tet results checkbox so that test results can be published to VSTS. This task executes the tests and publishes the test results to agent’s temp directory

Dotnet Test

  • Next we find the published test results file (*.trx) file to VSTS. We use the Publish task and change the Search folder to $(Agent.TempDirectory)

Publish Task

dotnet test task currently has results directory hardcoded to agent’s temp directory, which can be accessed using $(Agent.TempDirectory)

  • Next, we will publish the artifacts to VSTS. We add one more .NET Core task and select publish from the dropdown.

Dotnet Publish

We specify additional arguments like --configuration and set output directory as $(Build.ArtifactStagingDirectory) using--output argument. Notice, we also check `Add project name to publish path to publish artifacts in to their individual directories.

  • Finally, we add Publish Build Artifact task to publish all the contents from $(Build.ArtifactStagingDirectory) to VSTS.

Let’s queue a build and you should see all the artifacts published in nice structure within drop directory.

Artifacts

This was a small post to get you started with .NET core build pipeline in VSTS. Hope you found this post useful.


About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio, Visual Studio Code and Azure DevOps.
We Are
  • onlyutkarsh
    Utkarsh Shigihalli
    Microsoft MVP, Technologist & DevOps Coach


  • arora_tarun
    Tarun Arora
    Microsoft MVP, Author & DevOps Coach at Avanade

Do you like our posts? Subscribe to our newsletter!
Our Book