lib 中的 .DLL 和 .NET Core 2.0 SDK 中的 ref 文件夹有什么区别? [英] What's the difference between .DLLs in lib and ref folders in .NET Core 2.0 SDK?

查看:20
本文介绍了lib 中的 .DLL 和 .NET Core 2.0 SDK 中的 ref 文件夹有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET Core 2.0 SDK 中的每个 DLL 都有两个副本(它们具有不同的内容和文件大小).例如:

Each DLL in .NET Core 2.0 SDK comes in two copies (they have different content and file size). For instance:

c:Program Filesdotnetsdk2.0.0MicrosoftMicrosoft.NET.Build.Extensions et461 efSystem.Threading.Thread.dll"(14432 字节)

"c:Program Filesdotnetsdk2.0.0MicrosoftMicrosoft.NET.Build.Extensions et461 efSystem.Threading.Thread.dll" (14432 bytes)

c:Program Filesdotnetsdk2.0.0MicrosoftMicrosoft.NET.Build.Extensions et461libSystem.Threading.Thread.dll"(14352 字节)

"c:Program Filesdotnetsdk2.0.0MicrosoftMicrosoft.NET.Build.Extensions et461libSystem.Threading.Thread.dll" (14352 bytes)

它们之间有什么区别(以及拥有两个的目的)?

What's the difference between them (and the purpose of having two)?

推荐答案

所以正如 Hans Passant 已经提到的,引用"程序集是用来构建程序的,也就是说这是作为引用传递给编译器的程序集.然而,在运行时,实现可能会有所不同.除了框架本身,这可以被任何 NuGet 包使用,这些包分发单个编译时引用程序集,但为每个目标(.NET Core、.NET Framework、MonoAndroid 等)分发各种实现程序集.NuGet 包中的 lib 文件夹甚至可用于添加更多不希望使用应用程序直接引用的私有实现程序集.

So as Hans Passant already mentioned, "reference" assemblies are used to build programs, which means that this is the assembly that is passed to the compiler as a reference. At runtime however, the implementation might be different. Apart from the framework itself, this may be used by any NuGet package that distributes a single compile-time reference assembly but a variety of implementation assemblies for each target (.NET Core, .NET Framework, MonoAndroid etc.). The lib folder in NuGet packages can even be used to add more private implementation assemblies that it doesn't want consuming applications to reference directly.

参考程序集只有存根"方法,以便定义可用的 API 表面并可由编译器检查.

Reference assemblies only have "stub" methods so that the available API surface is defined and can be inspected by the compiler.

但是,您提到的是 Microsoft.NET.Build.Extensions 文件夹.它遵循 NuGet 包的结构(因为它是如何构建和集成到 SDK 中的),但它的用途与您使用的普通库完全不同.它用于允许 .NET Standard 库在部分兼容的 .NET Framework 版本上运行.它通过将实现程序集添加到构建输出中来工作 - 但这些是特殊的,因为它们只转发到相应的 .NET Framework 类型并添加 API 表面,为 .NET Standard 中可用的类型抛出 PlatformNotSupportedException但未由 .NET Framework 实现.例如..NET Standard 1.* 库将从 System.Runtime.dll 引用 System.Object,而 .NET Standard 2.0 库将从 netstandard.dll 引用它.Microsoft.NET.Build.Extensions 包含一个 System.Runtime.dll 和一个 netstandard.dll,其中包含要转发到的类型转发声明.NET Framework 的 mscorlib.dll.这对于其他类型和程序集的工作方式类似.

However, you are mentioning the Microsoft.NET.Build.Extensions folder. It follows the structure of a NuGet package (since that is how it is built and integrated into the SDK), but it has a completely different purpose than a normal library you'd use. It is used to allow .NET Standard libraries to run on partly-compatible versions of .NET Framework. It works by adding the implementation assemblies to the build output - but these are a special as they only forward to corresponding .NET Framework types and add API surface that throws PlatformNotSupportedExceptionfor types that are available in .NET Standard but not implemented by the .NET Framework. E.g. a .NET Standard 1.* library would reference System.Objectfrom System.Runtime.dll and a .NET Standard 2.0 library would reference it from netstandard.dll. The Microsoft.NET.Build.Extensions contains both a System.Runtime.dll and a netstandard.dll that contain type forwarding declarations to forward to .NET Framework's mscorlib.dll. This works similar for other types and assemblies.

这些程序集仅在必要时添加..NET Framework 4.7.1 将包含所有这些程序集和转发,因此不会将其他文件添加到构建输出中.

These assemblies are only added when necessary. .NET Framework 4.7.1 will contain all these assemblies and forwards so no additional files will be added to the build output.

这篇关于lib 中的 .DLL 和 .NET Core 2.0 SDK 中的 ref 文件夹有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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