Context
Although I understand that .NET Standard is a specification. I also understand that platforms (like .Core or Xamarin or UWP) conforms ("implements", "supports") picked version of .NET standard say 1.4 or 1.6. I also understand the .NET standard versions compatibility order.
Question
If I create a .NET Standard class lib in Visual Studio, and add some references, and compile it, then that particular compiled assembly must reference to concrete particular assemblies in a particular platform. However this way this assembly bound to that platform, this makes no sense.
So there must be a less hard "reference" metadata, this compiled assembly's references must be satisfied different assemblies (with the same strong name?) in different platform implementations, where the my assembly is about to run.
With all cloudy explanation what I miss really the explanation: How is this works in practice? The theory and analogies seem to be clear.
Missing I something?
All assemblies are compiled against a set of reference assemblies. This is true for all project types including .NET Standard, .NET Core and .NET Framework (and everything else.. except .NET <=3.5, but let's ignore that for simplicity).
.NET Standard defines a set of reference assemblies for each version that are used to compile .NET Standard assemblies against.
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 .NET Standard 2.0 then has an implementation assembly netstandard.dll
that either contains the type or contains type forwarding definitions. So for .NET Framework, there can be a netstandard.dll
that contains a type forward to [mscorlib]System.Object
. Another platform may have a different netstandard.dll
that for instance forwards to [System.Runtime]System.Object
.
In addition to netstandard.dll
there are a few more libraries that are there to support .NET Standard 1.0-1.6 and a few other type forwarding dlls that form a compatibility shim for .NET Framework applications (See Compatibility shim used by .NET Standard 2.0 for an explanation).
There is also some tooling in place to actually allow .NET Standard assemblies being used on platforms that do not contain these forwarding assemblies. The NETStandard.Library
NuGet package contains these for 1.0-1.6 and a new integrated MSBuild tooling adds support DLLs for .NET Framework 4.6.1+ for .NET Standard 1.5-2.0. .NET Framework 4.7.1 contains all the necessary assemblies so .NET Framework 4.7.1 projects do not need to add additional files to use .NET Standard assemblies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With