With .NET Core RC2, publishing Azure WebJob is a little bit different from the traditional(?) way, even it’s different from what RC1 does. In this post, we’ll walk through how to publish Azure WebJob using a .NET Core RC2 console application.
Sample code can be found at https://github.com/devkimchi/.NET-Core-for-Azure-WebJob-Sample.
Hello World Console Application
OK. First thing’s first. Let’s create a console app using .NET Core RC2. Take the latest copy from the repository above and build it on your local machine. Then run the console app like:
Then you can see the following:
Now, we’re ready to publish Azure WebJob with this.
In order to publish this console app, we need to do some more work beforehand. Azure WebJob looks for
run.cmd to run the console application as a webjob. Therefore, we need to create a file and name it as
run.cmd. The content is simply:
Wait. Can we run Azure WebApp with .NET Core RC2? Let’s double check. When you go to your Azure WebApp’s KUDU, you can confirm .NET Core RC2 has already been up and running.
We now don’t have to worry about that. Let’s keep preparing for publish. When we publish this console app, the
run.cmd doesn’t automatically get copied to the published directory. We need to include it by modifying
With this publish options, the
run.cmd file will be included to the published directory. The list of published files in the directory are:
We need to create a
.zip file and include all into the zip file. Once we complete, we’re ready to deploy this to Azure.
We assume this web job is a triggered webhook. If it is a scheduled one, we need to create a
settings.jobfile containing CRON schedule and include it for publish.
MSDeploy.exe is the easiest way. However, it needs too many parameters. Therefore, we’re going to use
WAWSDeploy. More details about
WAWSDeploy can be found here. With this, we only need the zip file we prepared and a publish settings file downloaded from Azure Portal. The publish settings file can be downloaded here:
We’re all set! Now, try the following command to deploy the web job:
Target directory will be
app_data\jobs\triggered\[WEBJOB_NAME]. If this web job is a continuously running one, replace
Now, we’ve deployed the web job to Azure!
Execution on Azure Portal
Once the web job is deployed to Azure, we can visually confirm that’s deployed.
Run this web job and see how the log looks like.
The console app as a web job has successfully run!