简体   繁体   English

在针对.NET Framework 4.7的WebJob中使用.NET Core 2.0库

[英]Using .NET Core 2.0 Libraries in WebJob Targeting .NET Framework 4.7

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. 我有一堆在.NET Core 2.0中创建的类库,我想在正在创建的新WebJobs项目中使用。 The WebJobs project targets .NET Framework 4.7. WebJobs项目以.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' 具有标识的程序集“ MyNetCore20Library”使用“ System.Runtime,版本= 4.2.0.0 ...”,其版本高于具有标识“ System.Runtime,版本= 4.1.2.0,文化”的引用程序集“ System.Runtime” =中立,PublicKeyToken = b03f5f11d50a3a'

Any idea how I can use my .NET Core 2.0 libraries in a new WebJobs project? 知道如何在新的WebJobs项目中使用.NET Core 2.0库吗?

PS Unfortunately, we can not yet create WebJobs in .NET Core which is why I'm trying to mix and match two frameworks. PS不幸的是,我们还不能在.NET Core中创建WebJobs,这就是为什么我试图混合和匹配两个框架的原因。 Not crazy about it but nevertheless I should be able to do it. 对此并不感到疯狂,但是我应该能够做到。

According to your description, I suggest you could try to use net core2.0 console application to create the web job. 根据您的描述,建议您尝试使用net core2.0控制台应用程序创建Web作业。

1.Created the net core 2.0 project. 1.创建了net core 2.0项目。

Then install the Microsoft.Azure.WebJobs(3.0.0-beta2) from Nuget Package manager. 然后从Nuget软件包管理器安装Microsoft.Azure.WebJobs(3.0.0-beta2)。

在此处输入图片说明

2.Change the console application's main method codes as below: 2.更改控制台应用程序的主要方法代码,如下所示:

using Microsoft.Azure.WebJobs; 使用Microsoft.Azure.WebJobs; using System; 使用系统; using System.IO; 使用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. 3.单击“发布”以发布控制台应用程序。

在此处输入图片说明

在此处输入图片说明

4.Locate the publishoutput folder and created a run.cmd file. 4.找到publishoutput文件夹并创建一个run.cmd文件。

Use the notepad to open the run.cmd and add below codes: 使用记事本打开run.cmd并添加以下代码:

dotnet {yourporjectname}.dll

Example: 例:

dotnet NetCore2Webjob.dll

5.Compress the whole publishoutput folder as zip file. 5.将整个publishoutput文件夹压缩为zip文件。

6.Open webjobs portal and upload this zip. 6.打开webjobs门户并上传此zip。

在此处输入图片说明

7.Wait the web app installed the webjob 7,等待网络应用安装了webjob

Result: 结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM