是否可以从 ASP.NET Core MVC 项目中引用 .net framework 4.7.2 类库? [英] Is it possible to reference .net framework 4.7.2 class library from an ASP.NET Core MVC project?

查看:59
本文介绍了是否可以从 ASP.NET Core MVC 项目中引用 .net framework 4.7.2 类库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的 ASP.NET MVC 5 项目,它也引用了一个 .NET Framework 4.7.2 类库,它生成了一些 CrystalReports.CrystalReports 不支持 .NET Core,因此类库将保留完整的 .NET Framework.

I have an ASP.NET MVC 5 project which works well and it also references a .NET Framework 4.7.2 Class library which produces some CrystalReports. CrystalReports does not support .NET Core, so the class library will stay with full .NET Framework.

现在,如果我将 ASP.NET MVC 5 升级到 ASP.NET Core 2(或 3),我是否能够引用类库并可能生成那些 CrystalReports?

Now, if I upgrade the ASP.NET MVC 5 to ASP.NET Core 2 (or 3), will I be able to reference the class library and possibly generate those CrystalReports?

推荐答案

.NET Core 不支持包含 .NET Framework 库.时期.但是,.NET Core 支持 .NET Standard,并且由于 .NET Framework 也实现了 .NET Standard,因此 Microsoft 在编译器中做了一个特殊的例外,允许您包含 .NET Framework 库,但需要注意的是它们实际上可能根本不起作用或完全.当您在 .NET Core 项目中包含 .NET Framework 库时,您会收到有关此效果的警告,您需要确保该库端到端正确运行.

.NET Core doesn't support inclusion of .NET Framework libraries. Period. However, .NET Core supports .NET Standard, and since .NET Framework also implements .NET Standard, Microsoft made a special exception in the compiler to allow you include .NET Framework libraries, with the caveat that they may not actually function at all or totally. You get a warning to this effect when you include a .NET Framework library in a .NET Core project, and it's on you to ensure that the library works correctly end-to-end.

大多数 .NET Framework 库可以工作,只要它们不使用特定于 .NET Framework 的 API(最显着的是特定于 Windows 的 API).如果他们这样做,那么他们将无法工作.

The largest majority of .NET Framework libraries do work, as long as they don't utilize .NET Framework-specific APIs (most notably Windows-specific APIs). If they do, then they will not work.

在这里,这个库似乎确实使用了 Windows 特定的 API,这意味着它与 .NET Core 不兼容.在这种情况下,您仍然可以创建 ASP.NET Core 项目,但您必须针对 .NET Framework,而不是 .NET Core.也就是说,直到 ASP.NET Core 3.0,它不能以 .NET Framework 为目标.ASP.NET Core 3.0+ 依赖于 .NET Standard 2.1,没有任何版本的 .NET Framework 支持或永远不会支持.

Here, it seems this library does utilize Windows-specific APIs, meaning it is incompatible with .NET Core. In such a situation, you can still create an ASP.NET Core project, but you must target .NET Framework, not .NET Core. That is, until ASP.NET Core 3.0, which cannot target .NET Framework. ASP.NET Core 3.0+ depends on .NET Standard 2.1, which no version of .NET Framework supports or ever will.

因此,如果您需要使用不 100% 符合 .NET Standard 2.0 的 .NET Framework 库,则必须以 .NET Framework 为目标,如果必须以 .NET Framework 为目标,则版本锁定在2.2 ASP.NET Core.

As such, if you need to use a .NET Framework library that is not 100% .NET Standard 2.0 compliant, you must target .NET Framework, and if you must target .NET Framework, you are then version-locked at 2.2 of ASP.NET Core.

更新

这个答案现在有点旧,但为了以防万一它仍然有用,我个人处理这种事情的方式是创建一个非常小而简单的 API.基本上,您创建一个面向 .NET Framework 的 ASP.NET Core 2.1 (LTS) 应用程序,该应用程序所做的就是与 .NET Framework 库进行交互.这意味着创建报告.然后,您可以自由地将实际应用创建为面向 .NET Core 的 ASP.NET Core 3.1+ 应用,您只需调用 API 即可获取数据、报告,以及您需要的任何内容.这有点像轻量级微服务方法.

This answer is a little old now, but just in case it might still be helpful, the way I've dealt with this kind of thing personally is to create a very small and simple API. Basically, you create a ASP.NET Core 2.1 (LTS) app targeting .NET Framework, and all this app does is interact with the .NET Framework library. Here that would mean creating the report. Then, you're free to create your actual app as an ASP.NET Core 3.1+ app targeting .NET Core, and you just call out to the API to get the data, report, whatever you need. It's sort of like a lightweight microservice approach.

这篇关于是否可以从 ASP.NET Core MVC 项目中引用 .net framework 4.7.2 类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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