Some Things I Learned While Getting Started with .NET Standard

Tags: .NET Standard;C#;

I recently created a new .NET library, which I wrote about here, and I decided to create it using the new .NET Standard library. I had read about .NET Standard when they announced it and read several articles that discussed it of which Rick Strahl’s article is a must read. As with many things new I ran into situations that caused me to dive deeper and gain a better understanding of what I was working with. I wanted to capture want I learned here as a reminder to myself and to help anyone else searching the internet as I was looking for answers.

I am not going to explain what .NET Standard is so if you want to learn more about it then I recommend you start by reading Rick Strahl’s article and then reading the MSDN documentation listed below.

My Observations

After creating a new .NET Standard library in Visual Studio I first noticed that there was no references item in the solution explorer. Instead there was a dependencies item which contained an SDK sub-item which itself contained an item called NETStandard.Library. When I expanded NETStandard.Library it contained a lot of libraries.

dependencies

To compare the differences of a .NET Framework library and a .NET Standard library I added a .NET Framework library to my solution and saw that it did have a references section which contained the standard core references. In the image below ClassLibrary is a .NET Framework library and Password is a .NET Standard library.

Standard versus Framework Librarys

The next difference I came across was when I went to add a reference. When I opened the Add Reference window I was presented with a message that said “No Framework assemblies were found on this machine”. I thought that was strange since I had just installed the RTM version of Visual Studio 2017 and I should have all the Framework libraries installed on my machine.

Add Reference Window

I did a quick google search and found out a few things.

  • That message in the Add Reference window is to be expected.
  • When you create a .NET Standard library the NETStandard.Library metapackage is automatically referenced during project creation. It is a set of standard .NET APIs that are prescribed to be used and supported together. This includes all of the APIs in the NETStandard.Platform package plus additional libraries that are core to .NET but built on top of NETStandard.Platform. What this means is you don’t need to need add references individually as you need them. If you go and look at your nuget packages you will see the NETStandard.Library.

NugetPackages

  • You may be asking what a metapackage is I know I was. Metapackages are a NuGet package convention for describing a set of packages that are meaningful together. They represent this set of packages by making them dependencies. They can optionally establish a framework for this set of packages by specifying a framework. Targeting a framework and implicitly referencing a metapackage means that you in effect are adding a reference to each of its dependent packages as a single gesture. That makes all of the libraries in those packages available for IntelliSense (or similar experience) and for publishing your app.
  • Here is the current table for .NET Platform support across all the different versions of .NET Standard.

.NET Platform Support

That is all for now, but as I continue to learn more about .NET Standard I will update this article.

Related Links

2 thoughts on “Some Things I Learned While Getting Started with .NET Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s