Why .NET Standard 2 build references many assemblies instead of single netstandard.dll assembly

后端 未结 1 1216
猫巷女王i
猫巷女王i 2021-01-27 18:38

Unlike .NET Standard 1, .NET Standard 2 introduces a single netstandard.dll reference assembly.

However, when compiling (with .NET Core SDK 2.2.203) with

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 18:51

    This is sadly due to history.

    You are right that in theory only netstandard.dll is needed to build a .NET Standard library.

    However, two things complicate this:

    1. .NET Standard 1.0-1.6 libraries used a lot more NuGet packages and thus assemblies. So a .NET Standard 1.6 library (.dll file) may contain references to e.g. System.Collections.Generic.dll to be resolvable. Also, the build system needs to know that classes that the 1.6 library expects in this dll is actually the same as the one in netstandard.dll.
    2. Existing .NET Framework libraries are allowed to be consumed from .NET Standard (and .NET Core) libraries without needing to be recompiled. This means that they also have been built for the .dll files that .NET Framework uses - from mscorlib.dll to the individual framework dlls.

    For both of these, references to assemblies with these names (and versions) are added which contain only type forward declarations. So for example mscorlib.dll would contain an empty System.Object entry that is marked with "go look for that in netstandard.dll".

    0 讨论(0)
提交回复
热议问题