Craftsman at work

I'm Artur Karbone, coding software architect and independent IT consultant and this is my blog about craftsmanship, architecture, distributed systems, management and much more.

.NET Core: Azure WebJobs Gotchas


I've just tried to publish a console application written in .NET Core and failed at first. Definitely some things have changed (last time i published a webjob before .NET Core was out). I kept getting the following error


and it dawned on me that a console application is no more exe file, just a dll. Meaning when you launch it either from Visual Studio or from command line

dotnet run  

all the magic is going on under the hood. It goes without saying that dll is not runnable per se and this why Azure failed to add such kind of a webjob.

I figured out two ways to resolve the issue.

Solution #1

Publish Self-contained app (all the components including .NET Core runtime are included in addition to exe file). To compile in Self-contained mode some additional steps are required - comment out/remove "type:platform" and add "runtimes" section in your project.json. Something like this:

  "dependencies": {
    "Microsoft.NETCore.App": {
      //"type": "platform",
      "version": "1.0.0"
  "runtimes": {
    "win7-x64": {}

Solution #2

Provide a script (like *.cmd, *.bat or any other runnable extension) to launch your app. Script body consists out of the following line:

dotnet <Your App Name>.dll  

This scenario has some gotchas too. You need to make sure that the script is among published artifacts. To achieve that use "buildOptions" in your project.json (so you can test it out locally in bin folder) and "publishOptions.include" sections (to have it as a published artifact):

 "buildOptions": {
    "emitEntryPoint": true,
    "copyToOutput": [ "exec.cmd" ]     
  "publishOptions": {
    "include": [ "exec.cmd" ]

That's it. If you want to play with these both cases, check out my github repo with a naive implementation of a webJob and runnable script.

comments powered by Disqus