简体   繁体   English

我可以使用 .NET Standard 来包装 .NET Core NuGet 包并使其在经典 .NET 中可用吗?

[英]Can I use .NET Standard to wrap .NET Core NuGet packages and make them available in classic .NET?

I am going through this blog post:我正在浏览这篇博文:

https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx

.. and its source code: .. 及其源代码:

https://github.com/ScarlettCode/Example https://github.com/ScarlettCode/Example

To my understanding, it wraps a .NET Core NuGet package (Microsoft.EntityFrameworkCore) in a .NET Standard library and makes it available for a classic .NET 4.6.1 application:据我了解,它将 .NET Core NuGet 包 (Microsoft.EntityFrameworkCore) 包装在 .NET Standard 库中,并使其可用于经典的 .NET 4.6.1 应用程序:

<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.0" />

Am I correct?我对么? Could that be a technique to wrap .NET Core NuGet packages in a .NET standard library can call them in classic .NET Framework 4.6.1 applications?这是一种将 .NET Core NuGet 包包装在 .NET 标准库中的技术,可以在经典的 .NET Framework 4.6.1 应用程序中调用它们吗?

Can I use .NET Standard to wrap .NET Core NuGet packages and make them available in classic .NET?我可以使用 .NET Standard 来包装 .NET Core NuGet 包并使其在经典 .NET 中可用吗?

Well, almost, but not quite.嗯,差不多,但不完全。

To my understanding, it wraps a .NET Core NuGet package (Microsoft.EntityFrameworkCore) in a .NET Standard library and makes it available for a classic .NET 4.6.1 application.据我了解,它将 .NET Core NuGet 包 (Microsoft.EntityFrameworkCore) 包装在 .NET Standard 库中,并使其可用于经典的 .NET 4.6.1 应用程序。

This is where you've misunderstood.这就是你误会的地方。 The package reference is for version 2.0.0 of Microsoft.EntityFrameworkCore.InMemory.包参考适用于 Microsoft.EntityFrameworkCore.InMemory 的 2.0.0 版。 We might consider this package to be "part of .NET Core" but in fact at a binary level the package targets .NETStandard 2.0.我们可能认为这个包是“.NET Core 的一部分”,但实际上在二进制级别,该包面向 .NETStandard 2.0。

How do I know the package targets .NET Standard 2.0?我怎么知道包的目标是 .NET Standard 2.0? I establish that by looking at the Dependencies section of its NuGet page or by consulting Fuget .我通过查看其NuGet 页面的 Dependencies 部分或咨询Fuget 来确定这一点

.NET 4.6.1* and .NET Core 2.0 both support .NET Standard 2.0 , that is to say both of those frameworks (and newer versions) can reference .NET Standard 2.0 libraries. .NET 4.6.1* 和 .NET Core 2.0 都支持 .NET Standard 2.0 ,也就是说这两个框架(和更新版本)都可以引用 .NET Standard 2.0 库。

So let's go back to your original question:那么让我们回到你最初的问题:

Can I use .NET Standard to wrap .NET Core NuGet packages and make them available in classic .NET?我可以使用 .NET Standard 来包装 .NET Core NuGet 包并使其在经典 .NET 中可用吗?

No, but you can package your code up in libraries which target .NET Standard, and use those libraries from .NET Core projects AND .NET Framework projects;不,但您可以将代码打包到面向 .NET Standard 的库中,并使用来自 .NET Core 项目和 .NET Framework 项目的库; and likewise you can reference Nuget packages in .NET Framework projects provided they target .NET Standard even if the package has 'Core' in the name and you think of it as being part of .NET Core .同样,您可以在 .NET Framework 项目中引用 Nuget 包,前提是它们以 .NET Standard 为目标,即使包的名称中有“Core”并且您认为它是 .NET Core 的一部分 This is the beauty of .NET Standard.这就是 .NET Standard 的美妙之处。

The key takeaway here is to pay close attention to the Dependencies section of Nuget description pages!这里的关键是密切关注 Nuget 描述页面的依赖关系部分!


*Note that whilst .NET 4.6.1 officially supports .NET Standard 2.0, Microsoft recommend using 4.7.2 or higher. *请注意,虽然 .NET 4.6.1 正式支持 .NET Standard 2.0,但 Microsoft 建议使用 4.7.2 或更高版本。 See my answer here for more information.在此处查看我的回答以获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET标准程序集:创建可以由.NET Core和本地Nuget.Server托管的完整.NET使用的nuget程序包。 - .NET standard assemblies: create nuget packages that can be used by .NET Core and full .NET hosted by local Nuget.Server 我可以使用在.NET Standard 2.0中为.NET Framework编写的包吗? - Can I use packages written for .NET Framework in .NET Standard 2.0? 更新到.NET Standard 2.0 Nuget软件包 - Updating to .NET Standard 2.0 Nuget packages .NET Standard NuGet 包是如何实现的? - How are .NET Standard NuGet packages implemented? 我可以在经典的 .NET 4.6.1 应用程序中使用 .NET Standard 2.0 包吗? - Can I use a .NET Standard 2.0 package in a classic .NET 4.6.1 application? 在.NET Standard项目中使用Package References后,如何恢复在packages.config中引用Nuget包? - How can I revert to referencing Nuget packages in packages.config after using Package References in a .NET Standard project? 面向 .NET Standard 时,我到底可以在我的项目中使用 .NET Core 和 .NET Framework 中的哪些内容? - When targeting .NET Standard, what exactly can I use from .NET Core and .NET Framework in my project? .NET标准库能否以某种方式使用支持.NET Framework 4.6.1的nuget包 - Can .NET standard libraries somehow consume nuget packages, which support .NET Framework 4.6.1 当我从.NET 461中引用.NET Standard NuGet时,为什么要添加成吨的软件包? - Why are tons of packages added when I reference a .NET Standard NuGet from within .NET 461? 可以将.NET与经典ASP一起使用吗? - Can I use .NET with classic ASP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM