Saturday 15 December 2018

.NET Core: Azure WebJobs Gotchas

Problem

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
alt
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 repowith a naive implementation of a webJob and runnable script.

1 comment:

  1. Pleasantly surprised by the discovery of your site so pretty and so original, everything is well designed and very beautiful with many choices, it is a wonder! your creations are beautiful and what to say of your papers -lettre, superb !! Congratulations. Sincerely.

    voyance en ligne gratuite

    ReplyDelete

Angular Tutorial (Update to Angular 7)

As Angular 7 has just been released a few days ago. This tutorial is updated to show you how to create an Angular 7 project and the new fe...