Inside a .NET Core project, you specify the frameworks that you wish to target. What are these frameworks? Well, .NET Core itself, but the classic .NET Framework as well, Xamarin, Universal Windows Platform (UWP), Portable Class Libraries (PCL), Mono, Windows Phone, and more.
In the early days of .NET Core, you would either target .NET Core itself, or/as well as one of these other frameworks. Now it is advisable to target standards instead. Now we have .NET Standard, and the differences between the two are as follows:
.NET Standard is a specification (a contract) that covers which APIs a .NET platform has to implement.
.NET Core is a concrete .NET platform and implements the .NET Standard.
The latest .NET Standard will always cover the highest .NET full framework released.
This should make it very easy to understand. As you can see, all .NET APIs that need Windows (WPF, Windows Forms, Drawing) are only available in a specific platform (.NET 4.5), not a standard. Standards are for cross-platform functionality.
So instead of targeting a specific version, such as .NET 4.5.1, .NET Core 1.0, Mono, Universal Windows Platform 10, you should target a .NET Standard. Your project is guaranteed to work on all platforms that support that standard (or a higher one), either existing or waiting to be created. You should try to keep your dependency to the lowest standard possible to increase the number of platforms that your app will work on, if that is important to you.
The current mapping between the different .NET frameworks and the .NET Standard they implement at the time this book was written is always available at https://github.com/dotnet/standard/blob/master/docs/versions.md.
.NET Core 2.0 and .NET Standard 2.0 were made available in August 2017, and now four frameworks target .NET Standard 2.0:
.NET Framework full
.NET Core 2.x
Xamarin
Mono
.NET Core 3.0 was made available on September 2019 and with it .NET Standard 2.1.
You can have your dependencies specified per target or for all targets. In the former case, all of the dependencies need to support all of the targets, and in the latter, we can have different dependencies for each target. You'll probably want a mix of the two, with common libraries as global dependencies and more specialized libraries specified only where available. If you target more than one standard (or framework), then pay attention, because you may have to resort to conditional definitions (#if) to target those features that only exist in one of them. Let's see how.
It is important that you know that you can target the full .NET framework in an ASP.NET Core application! However, if you do this, you will lose the platform independence—that is, you will only be able to run it on Windows.
By default, an ASP.NET Core project targets netcoreapp1.x, netcoreapp2.x, or netcoreapp3.x, depending on whether you are targeting ASP.NET Core 1.x, 2.x, or 3.x, but you can change it in the .csproj file. If you just want to target one framework, then modify the TargetFramework element like this:
<TargetFramework>net461</TargetFramework>
Or, if you want to target more than one, replace TargetFrameworkwith TargetFrameworks :