.Net Core Console Application as an Azure WebJob

An Azure WebJob allows you to run a background job in the same context as you App Service. The job can either run continuously or triggered (manually triggered or on a schedule).

A WebJob can run the following file types: cmd, bat, exe, ps1, sh, php, py , js or jar.

However, a .Net Core Console application does not create an exe file, or any of the other commands expected by the WebJob. To run a.Net Core Console application you use the dotnet command.

So create a new cmd file in your project, e.g.: run.cmd. In the file just add the following command (substituting myapplication.dll with your dll).

dotnet myapplication.dll

On the properties of the file make sure the ‘Copy to Output Directory’ is set to ‘Copy Always’

When you build the console application the run.cmd file will be included in the output directory. The WebJob will use this to run your console application.

See https://docs.microsoft.com/en-us/azure/app-service/web-sites-create-web-jobs for detailed instructions on setting up a WebJob in Azure;

Note: You need to make sure the cmd file is correctly encoded as a UTF-8 file without BOM (by order marks). You can check for this using Notepad++ by using the encoding menu.

See https://stackoverflow.com/questions/40591418/missing-dotnet-exe-in-azure-webjob for more details.

Alex Orpwood Written by:

Software developing and architecting for 20 years. Satellite monitoring by day, writing my own app by night. More about me