2017-08-30 134 views
0

我有一堆在.NET Core 2.0中创建的类库,我想在我创建的新WebJobs项目中使用它。 WebJobs项目的目标是.NET Framework 4.7。在WebJob中使用.NET Core 2.0库定位.NET Framework 4.7

当我尝试引用他们,我得到一条错误:

大会 'MyNetCore20Library' 与身份...使用“System.Runtime, 版本= 4.2.0.0 ...其中有更高版本比引用的程序集 “System.Runtime”有身份“System.Runtime,版本= 4.1.2.0, 文化=中性公钥= b03f5f11d50a3a”

任何想法,我怎么可以用我的.NET的核心新WebJobs项目中的2.0库?

P.S.不幸的是,我们还不能在.NET Core中创建WebJobs,这就是为什么我要混合和匹配两个框架。不是疯狂的,但我应该能够做到这一点。

回答

2

根据您的描述,我建议您可以尝试使用net core2.0控制台应用程序来创建Web作业。

1.创建net core 2.0项目。

然后从Nuget Package manager安装Microsoft.Azure.WebJobs(3.0.0-beta2)。

enter image description here

2.Change控制台应用程序的main方法如下代码:

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

enter image description here

enter image description here

4.Locate的publishoutput文件夹,并创建了一个run.cmd文件。

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

dotnet {yourporjectname}.dll 

例子:

dotnet NetCore2Webjob.dll 

5.Compress整个publishoutput文件夹中的zip文件。

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

enter image description here

7。等待Web应用程序安装在webjob

结果:

enter image description here

+0

太好了!谢谢!我只有一个问题需要解决:使用DI - 优先通过Ninject。这是我在这个问题上的其他帖子:https://stackoverflow.com/questions/45968628/using-ninject-in-net-core-console-app再次感谢您的帮助。 – Sam

+0

随着我进一步发展,看起来我仍然需要在.NET Framework中创建我的WebJob,因为我需要'mscorlib',它似乎是.NET Framework的一部分。你确定这个解决方案会起作用吗?看到我的其他帖子在这里:https://stackoverflow.com/questions/46017931/no-parameterless-constructor-error-in-webjobs-with-net-core-and-ninject?noredirect=1#comment79131285_46017931 – Sam