blog post image
Andrew Lock avatar

Andrew Lock

~4 min read

What is the NETStandard.Library metapackage?

In my last post, I took a quick look at the Microsoft.AspNetCore meta package. One of the libraries referenced by the package, is the NETStandard.Library NuGet package. In this post I take a quick look at this package and what it contains.

If you're reading this post, you have hopefully already heard of .NET Standard. This is acts as an interface to .NET Platforms, and aims to define a unified set of APIs that those platforms must implement. It is the spiritual successor to PCLs, and allow you to target .NET Framework, .NET Core, and other .NET platforms with the same library code base.

The NETStandard.Library metapackage references a set of NuGet packages that define the .NET Standard library. Like the Microsoft.AspNetCore package from my last post, the package does not contain dlls itself, but rather references a number of other packages, hence the name metapackage. Depending on the target platform of your project, different packages will be added to the project, in line with the appropriate version of .NET Standard the platform implements.

For example, the .NET Standard 1.3 dependencies for the NETStandard.Library package includes the System.Security.Cryptography.X509Certificates package, but this does not appear in the 1.0, 1.1 or 1.2 target platforms. You can also see this on the nuget.org web page for the package.

It's worth noting that the NETStandard.Library package will typically be referenced by projects, though not by libraries. It's also worth noting that the version number of the package does not correspond to the version of .NET Standard, it is just the package version.

So even if your project is targeting .NET Standard version 1.3 (or multi-targeting), you can still use the latest NETStandard.Library package version (1.6.1 at the time of writing). The package itself is versioned primarily because it also contains various tooling support such as the list of .NET Standard versions.

It's also worth bearing in mind that the NETStandard.Library is essentially only an API definition, it does not contain the actual implementation itself - that comes from the underlying platform that implements the standard, such as the .NET Framework or .NET Core.

If you download one of the packages referenced in the NETStandard.Library package, System.Collections for example, and open up the nuget package as before, you'll see there's a lot more too it than the Microsoft.AspNetCore metapackage. In particular, there's a lib folder and a ref folder:

System.Collections 4.3

In a typical NuGet package, lib is where the actual dlls for the package would live. However, if we do a search for all the files in the lib folder, you can see that there aren't actually any dlls, just a whole load of empty placeholder files called _._ :

Lib folder

So if there aren't any dlls in here, where are they? Taking a look through the ref folder you find a similar thing - mostly _._ placeholders. However that's not entirely the case. The netstandard1.0 and netstandard 1.3 folders do contain a dll (and a load of xml metadata files):

Refs folder

But look at the size of that System.Collections.dll - only 42kb! Remember, the NETStandard.Library only includes reference assemblies, not the actual implementations. The implementation comes from the final platform you target; for example .NET Framework 4.6.1, .NET Core or Mono etc. The reference dlls just define the various APIs that these platforms must expose for a given version of .NET Standard.

You can see this for yourself by decompiling the contained dll using something like ILSpy. If you do that, you can see what looks likes the source code for System.Collections, but without any method bodies, showing that this really is just a reference assembly:

ILSpy of System.Collections

These placeholder assemblies are are a key part of the the .NET Standard infrastructure. They provide concrete APIs against which you can compile your projects, without tying you to a specific implementation (i.e. .NET Framework or .NET Core).

Final thoughts

If this all seems confusing and convoluted, that's because it is! It doesn't that every time you think you've got your head around it, things have moved on, are being changed or improved…

Having said that, most of this is more detail than you'll need. Generally, it's enough to understand the broad concept of .NET Standard, and the fact that it allows you to share code between multiple platforms.

There's a whole host of bits I haven't gone into, such as type forwarding, so if you want to get further into the details, and really try to understand what's going on, I suggest checking out the links below. In particular, I highly recommend the video series by Immo Landwerth on the subject.

Of course, when .NET Standard 2.0 is out, all this will change again, so brace yourself!

Andrew Lock | .Net Escapades
Want an email when
there's new posts?