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

查看:134
本文介绍了在针对.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,Version = 4.1.2.0,
Culture = neutral,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?

PS不幸的是,我们尚不能在.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作业。

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。等待网络应用安装了webjob

7.Wait the web app installed the webjob

结果:

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

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