在面向 .NET Framework 4.7 的 WebJob 中使用 .NET Core 2.0 库 [英] Using .NET Core 2.0 Libraries in WebJob Targeting .NET Framework 4.7

查看:29
本文介绍了在面向 .NET Framework 4.7 的 WebJob 中使用 .NET Core 2.0 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆在 .NET Core 2.0 中创建的类库,我想在我创建的新 WebJobs 项目中使用它们.WebJobs 项目面向 .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. The WebJobs project targets .NET Framework 4.7.

当我尝试引用它们时,出现如下错误:

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

使用标识组装MyNetCore20Library"......使用System.Runtime,Version=4.2.0.0... 比引用的程序集版本更高'System.Runtime' 标识为 'System.Runtime,版本 = 4.1.2.0,文化=中性,PublicKeyToken=b03f5f11d50a3a'

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'

知道如何在新的 WebJobs 项目中使用我的 .NET Core 2.0 库吗?

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

附言不幸的是,我们还不能在 .NET Core 中创建 WebJobs,这就是我尝试混合和匹配两个框架的原因.不为它疯狂,但无论如何我应该能够做到.

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.

推荐答案

根据你的描述,我建议你可以尝试使用net core2.0控制台应用来创建web job.

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

1.创建net core 2.0项目.

1.Created the net core 2.0 project.

然后从 Nuget 包管理器安装 Microsoft.Azure.WebJobs(3.0.0-beta2).

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

2.更改控制台应用程序的主要方法代码如下:

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

使用 Microsoft.Azure.WebJobs;使用系统;使用 System.IO;

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.单击发布以发布控制台应用程序.

3.Click publish to publish the console application.

4.找到publishoutput文件夹并创建一个run.cmd文件.

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

使用记事本打开run.cmd并添加以下代码:

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

dotnet {yourporjectname}.dll

示例:

dotnet NetCore2Webjob.dll

5.将整个publishoutput文件夹压缩为zip文件.

5.Compress the whole publishoutput folder as zip file.

6.打开 webjobs 门户并上传此 zip.

6.Open webjobs portal and upload this zip.

7.等待 web 应用安装 webjob

7.Wait the web app installed the webjob

结果:

这篇关于在面向 .NET Framework 4.7 的 WebJob 中使用 .NET Core 2.0 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆