问题
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.
回答1:
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.
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.
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.
7.Wait the web app installed the webjob
Result:
来源:https://stackoverflow.com/questions/45950157/using-net-core-2-0-libraries-in-webjob-targeting-net-framework-4-7