在标准.net控制台应用程序中使用.Net Core dll [英] Using .Net Core dll in standard .net Console app

查看:180
本文介绍了在标准.net控制台应用程序中使用.Net Core dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用.NET Core 2.1在VS 2017中构建了一个类库。
现在,我想在.NET Framework 4.6.2内置的标准控制台应用程序中使用该dll。

I have built a class library in VS 2017 using .NET Core 2.1. Now, I want to use that dll in a standard console app built in .NET framework 4.6.2.

当我引用.NET Core dll时在控制台应用程序中,我收到此错误:

When I refer to the .NET Core dll in the console app, I am getting this error:


未处理的异常:System.IO.FileLoadException:无法加载文件
或程序集 System.Runtime,版本= 4.2.1.0,区域性=中性,
PublicKeyToken = b03f5f7f11d50a3a或其依赖项之一。
位于的程序集的清单定义与程序集
引用不匹配。 (来自HRESULT的异常:0x80131040)位于
Marketo_Console.Program.Main(String [] args)

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Marketo_Console.Program.Main(String[] args)

如何解决此问题?如何在标准控制台应用程序中使用.NET Core dll?

How to resolve this? How can I use a .NET Core dll in a standard console app?

推荐答案


如何解决这个?

How to resolve this?

您不能。至少不是直接。

You cannot. At least not directly.


  • .NET Core可以运行针对.NET Core本身或.NET Standard的程序集。

  • 。 NET Framework可以运行针对.NET Framework本身或.NET Standard的程序集。

因此,没有办法带来两个针对Full的程序集框架和核心分别在一起。不在Core中,也不在完整框架中。 (您也许可以找到黑客和但对我来说,这是可行的解决方案,但是对于特定的用例,它们是非常脆弱的例外。)

So there is no way to bring two assemblies that target Full Framework and Core respectively together. Not in Core and not in full framework. (You might be able to find hacks and "but for me this works" solutions all over the place, but they are super brittle exceptions for their specific use case).

您可以 将.NET Core程序集的目标框架切换到.NET Framework或.NET Standard,或者可以提供多个个目标框架来构建Nuget包支持.NET Core 完整框架。

You could switch your target framework of the .NET Core assembly to either .NET Framework, or to .NET Standard, or you could give multiple target frameworks to build a Nuget package that supports .NET Core and full framework.

但是如果您需要.NET Core程序集 .NET Framework应用程序,则不能以这种方式一起使用它们。

But if you need a .NET Core assembly and a .NET Framework application, you cannot use them together that way.

这篇关于在标准.net控制台应用程序中使用.Net Core dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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