Friday, 26 August 2016

Auto publish Azure Web Jobs with ASP.Net Core RTM

This is an update of my original post on how to do this with ASP.Net Core RC1
At the time of this writing, there is no tooling to auto publish Azure Web Jobs with an ASP.Net Core website. You can do it with old-style websites, but not yet the new ones. The tooling is highly likely to appear eventually, but as of right now you have to take a few steps to set it up yourself, which is what I describe in this post. For clarity, what I am describing works only with source control deploy (git etc), not with publishing from Visual Studio.

This information will eventually become obsolete, probably around the RTM of the ASP.Net Core Visual Studio tooling. If that has happened and I have not updated the post, please post a comment and I'll get on it.
Note that for very simple, self-contained web jobs, there may be a simpler approach (see for some thoughts). In this post I am catering for the scenario where your webjob references another project in your solution - though it'll work just as well if it doesn't.

In summary

You have to use a custom deployment script and insert an action to publish your webjob to the path that Azure looks for webjobs in; App_Data/Jobs/Continuous for continuous jobs. Azure will automatically detect content in that folder and assume it's a webjob, so all we really have to do is make sure our webjob is copied there. And yes, it will happily overwrite a running webjob, the Kudu functionality handles that somehow.

The reason we are publishing, using dotnet publish, is to ensure we get all the dependencies. It won't re-compile so it's just a copy operation.
If we had a very simple webjob that was self contained, you could just copy the files, as long as you added a run.cmd (see link above).

In detail

Prepare a site
  1. Set up a solution with an ASP.Net 5 Web site and a webjob written as a ASP.Net 5 / Core console app.
  2. Set up source control deploy to an Azure website. It shouldn't matter which type.
  3. Wait for the initial deploy of the site. 

Set up a custom deployment script

In this example, we will download the deployment script that Azure has created. There are ways to also do this with the Azure CLI, but the generated script is not quite the same at this point in time - which may or may not matter.
  1. Get the auto generated script
    1. Log in to the web app console at https://[yoursite]
    2. Go to Tools - Download deployment script
    3. Unzip the downloaded zip file to the root of your solution folder
  2. Modify your deploy.cmd file in the following ways
    1. Add a line like this near the top - just to make it easier to check that your custom script is being used (whatever you put after echo will be output in the log file)
      echo CUSTOM SCRIPT Start
    2. Near the middle of the file you will find a series of steps that are numbered. One of the steps will look like this;
      NOTE: The indented lines will be on a single line, the line breaks are only added here for readability
      :: 2. Build and publish
      call :ExecuteCmd "%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\MySolution.sln" 
    3. Below that insert these lines (updating the path with the actual path to your webjob in the solution)
      NOTE: The indented lines need to put on a single line, the line breaks are only here for readability
      :: 2.1 Publish webjobs
      call :ExecuteCmd dotnet publish 
               -o "%DEPLOYMENT_TEMP%\App_Data\Jobs\Continuous\MyWebJob" 
             -c Release
      If you have more than one web job, just add individual publish lines for each one

Check that it worked

Push your changes and wait for Azure to deploy, then look at the webjobs in the Azure portal. You should see your job there. In case you don't, have a look at the publish log file to see if there are any errors in there.


  1. Today, that same £8,000 is more likely to be used as a deposit on a car which could be worth many tens of thousands, followed by up to five years of monthly payments.More Help

  2. Back in the day, when auto shipping international was new, the risks were higher and so were the costs. Not a lot of individuals could ship their cars to unfamiliar territory and the process of doing so would take weeks, sometimes months. Visit This Link

  3. In specialized terms there are three key highlights of responsive web design, the mystery fixing is for the most part thought to be media web design

  4. I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.
    dot-net training in chennai

  5. Web development significantly manages the usefulness of the website and it can be utilized to incorporate diverse usefulness in the website. web development frameworks

  6. You should be flawlessly certain and characterize your objectives in advance, before you really sign a web design benefit contract with a designer.bahrain web development

  7. Only after the job is approved to this stage, does job application become a personnel process. But not recognising the human beings wholly in the personal exchange - the manager and the successful jobholder - is a key mistake of many job applicantsThis Article

  8. Immensely beguiled by the words used by the writer.