在标准.net控制台应用程序中使用.Net Core dll

编程入门 行业动态 更新时间:2024-10-10 13:16:21
本文介绍了在标准控制台应用程序中使用.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

本文发布于:2023-11-05 02:42:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559692.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   标准   net   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!