Date posted: 17 Aug 2019, 1 minutes to read

Run .NET Core programs in Azure DevOps

Recently I wanted to build and run a .NET core console application in Azure DevOps and found out you cannot do that with the default .NET core tasks.

unsplash-logoPhoto by Sam Truong Dan

The default tasks in Azure DevOps and tutorials are more geared towards web-development and publishing a zip file that can be used with a WebDeploy command.

For an application,I would have thought that you could run the compiled assembly by calling dotnet run path-to-assembly on it. Turns out that the run command is used to run the code from a project, not from a compiled assembly (see the docs).

You can just call dotnet path-to-assembly, but the .NET core tasks in Azure DevOps will not let you do that: you can select a custom command, but you cannot leave that command empty for example.

Option 1: Publish the application to self-contained

Here’s how to go around that limitation: publish the application for the platform(s) you want to run: that way you’ll have an executable that can be executed with a PowerShell task. I choose the Windows platform as a target and published the files to a separate publish folder. Azure Build Pipeline overview.

You can then run it in a release. The release just consists of extracting the build artefact, overwriting the application settings with an Azure DevOps Extension and running the executable.

Azure Release Pipeline Task running the executable

Option 2: Run the assembly

An even easier way to run the assembly is to call the dotnet command on the assembly itself, just do it in a PowerShell task:

Azure Release Pipeline with Task calling the assembly