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

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

问题描述

.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 Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\ net461\ref\System.Threading.Thread.dll(14432字节)

"c:\Program Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\System.Threading.Thread.dll" (14432 bytes)

c:\Program Files\dotnet\sdk\2.0。 0\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Threading.Thread.dll(14352字节)

"c:\Program Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Threading.Thread.dll" (14352 bytes)

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

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

推荐答案

因此,正如Hans Passant已经提到的那样,使用了引用程序集生成程序,这意味着这是作为参考传递给编译器的程序集。但是,在运行时,实现可能有所不同。除了框架本身之外,任何分发单个编译时参考程序集但为每个目标(.NET Core,.NET Framework,MonoAndroid等)提供各种实现程序集的NuGet包都可以使用此框架。 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表面,该表面会抛出 PlatformNotSupportedException 在.NET Standard中可用,但未由.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.

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

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