Vaguely about .NET Standard vs .NET Core "interface versus implementation" explanations

Context

Although I understand that .NET Standard is a specification. I also understand that platforms (for example, Core or Xamarin or UWP) correspond ("implements", "support") to the selected version of the .NET standard, say 1.4 or 1.6. I also understand the compatibility order of standard .NET versions.

Question

If I create a .NET class of the .NET class in Visual Studio and add some references and compile it, then this assembly assembly must reference specific concrete assemblies on a specific platform. However, this method associated with this platform does not make sense.

Thus, there should be less rigid "link" metadata, these compiled assembly links must satisfy different assemblies (with the same strong name?) In different implementations of the platform where my assembly is assembled.

With all the cloudy explanation that I missed, there really is an explanation: how does this work in practice? Theory and analogy seem clear.

Missing something?

+5
source share
1 answer

All assemblies are compiled against a set of reference assemblies. This is true for all types of projects, including the .NET Standard, .NET Core and .NET Framework (and everything else), except for .NET <= 3.5, but do not pay attention to this for simplicity).

.NET Standard defines a set of referenced assemblies for each version that are used to compile .NET Standard assemblies.

For .NET Standard 2.0, the most notable reference assembly is netstandard.dll . If you reference System.Object , the compiler will emit IL code referencing [netstandard]System.Object .

Any platform that "conforms" to the .NET Standard 2.0 standard has a netstandard.dll implementation assembly that either contains a type or contains type forwarding definitions. Thus, for the .NET Framework there may be netstandard.dll , which contains the forward type for [mscorlib]System.Object . Another platform may have another netstandard.dll , which, for example, is forwarded to [System.Runtime]System.Object .

In addition to netstandard.dll there are several more libraries that support .NET Standard 1.0-1.6 and several other types of DLL forwarding that form compatibility for .NET Framework applications (see Compatibility used by .NET Standard 2.0 for an explanation).

There are also some tools that can actually enable .NET Standard assemblies used on platforms that do not contain these forwarding assemblies. The NETStandard.Library NuGet package contains them for 1.0-1.6, and the new integrated MSBuild tool adds support DLLs for the .NET Framework 4.6.1+ for .NET Standard 1.5-2.0..NET Framework 4.7.1 contains all the necessary assemblies, so for projects .NET Framework 4.7.1 there is no need to add additional files to use the .NET Standard collections.

+7
source

Source: https://habr.com/ru/post/1271923/


All Articles