Code tested on .NET Core RTM 1.0.1 with Tooling Preview2 and Azure SDK 2.9.5
I love WebJobs. You deploy a website, you need a few tasks to be run on the side to ensure that everything is running smoothly or maybe un-queue some messages and do some actions.
How to do it in ASP.NET 4.6.2? Easy. Visual Studio is throwing you menus, wizards, blog posts and what not at you to help you start using it. The tooling is curated to make you fall into a pit of success.
With .NET Core tooling still being in preview, let’s just say that there’s no menus nor wizards to help you out. I haven’t seen anything online that help you automate the “Publish“ experience.
WebJobs are easy. If you forget the Visual Studio tooling for a moment, WebJobs are run by Kudu.
Kudu is the engine behind most of Azure WebApps experience from deployments to WebJobs. So how does Kudu detect that you have WebJobs to run? Well, everything you need to know is on their wiki.
Basically, you will have a command file named
run (with various supported extensions) located somewhere like this:
If that file is present? Bam. WebJob created with the
jobName. It will automatically show in your Azure Portal.
Let’s take this
run.cmd for example:
The simplest way is to create a CRON schedule. This can be done by creating a
settings.job file. This file is basically all the WebJobs options. One of them is called schedule.
If you want to trigger a job every hour, just copy/paste the following in your
- One ASP.NET Core application project ready to publish
run.cmdfile and a
- One .NET Core Console Application
To make sure it runs, we need to ensure that we publish the
app_data folder. So add/merge the following section to your
If you deploy this right now, your web job will run every hour and echo
Let’s make it useful.
First let’s change
Or if your application doesn’t specify a
runtimes section in your
The last part is where the fun begins. Since we are publishing the WebApp, those executable do not exist. We need to ensure that they are created.
There’s a section in your
project.json that runs right after publishing the ASP.NET Core application.
Let’s publish our WebJob directly into the proper
Congratulation! You now have a .NET Core WebJob published in your ASP.NET Core application on Azure that runs every hour.
All those console application are of course runnable directly locally or through the Azure scheduled trigger.
If this post helped, let me know in the comments!