0

I have a bunch of class libraries created in .NET Core 2.0 that I'd like to use in a new WebJobs project I'm creating. The WebJobs project targets .NET Framework 4.7.

When I try to reference them, I get an error that reads:

Assembly 'MyNetCore20Library' with identity ... uses 'System.Runtime, Version=4.2.0.0... which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f11d50a3a'

Any idea how I can use my .NET Core 2.0 libraries in a new WebJobs project?

P.S. Unfortunately, we can not yet create WebJobs in .NET Core which is why I'm trying to mix and match two frameworks. Not crazy about it but nevertheless I should be able to do it.

Sam
  • 26,817
  • 58
  • 206
  • 383

1 Answers1

2

According to your description, I suggest you could try to use net core2.0 console application to create the web job.

1.Created the net core 2.0 project.

Then install the Microsoft.Azure.WebJobs(3.0.0-beta2) from Nuget Package manager.

enter image description here

2.Change the console application's main method codes as below:

using Microsoft.Azure.WebJobs; using System; using System.IO;

namespace NetCore2Webjob
{
    class Program
    {
        static void Main(string[] args)
        {
            Environment.SetEnvironmentVariable("AzureWebJobsDashboard", "connection");
            Environment.SetEnvironmentVariable("AzureWebJobsStorage", "storage connection");
            var config = new JobHostConfiguration();

            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            var host = new JobHost(config);
            host.RunAndBlock();
        }


    }
    public class Functions
    {
        public static void ProcessQueueMessage([QueueTrigger("myqueue")] string message, TextWriter log)
        {
            log.WriteLine(message);
        }
    }
}

3.Click publish to publish the console application.

enter image description here

enter image description here

4.Locate the publishoutput folder and created a run.cmd file.

Use the notepad to open the run.cmd and add below codes:

dotnet {yourporjectname}.dll

Example:

dotnet NetCore2Webjob.dll

5.Compress the whole publishoutput folder as zip file.

6.Open webjobs portal and upload this zip.

enter image description here

7.Wait the web app installed the webjob

Result:

enter image description here

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
  • Great! Thank you! I have only one more problem to solve: using DI -- preferebly through Ninject . Here's my other post on this issue: https://stackoverflow.com/questions/45968628/using-ninject-in-net-core-console-app Thanks again for your help with this. – Sam Aug 30 '17 at 19:52
  • As I advanced more, it looks like I still need to create my WebJob in .NET Framework because I need `mscorlib` which seems to be a part of .NET Framework. Are you sure this solution will work? See my other post here: https://stackoverflow.com/questions/46017931/no-parameterless-constructor-error-in-webjobs-with-net-core-and-ninject?noredirect=1#comment79131285_46017931 – Sam Sep 06 '17 at 21:41