Last week, .NET Core 2.0 preview 1 was announced along with ASP.NET Core 2.0 and .NET Standard 2.0. There are lots of new stuff to play with, but this post is focuses on .NET standard 2.0. At the time of writing this post, it is preview 1 release of .NET standard 2.0 and it’s impressive. This post talks about installing .NET standard 2.0 and find out what’s new in .NET Standard 2.0.
What’s new in .NET Standard 2.0
.NET Standard is a standard that represents a set of APIs that all .NET platforms have to implement. Don’t confuse yourself with .NET Core. .NET Core is a platform which implements .NET Standards. Take a look at below video, Immo Landwerth explains what, why and where about .NET Standard.
This new release of .NET Standard addresses couple of problems with current version of .NET Standard (1.6). The current version has following issues,
- Not enough APIs – The current version (1.6) of .NET Standard doesn’t have enough APIs which makes almost impossible to port your existing .NET Framework application code to .NET Core. For example, If your existing code is using dataset, you can’t directly move your code to .NET Core.
- Issue with third-party library – If the consumed third-party library doesn’t implement .NET Standard (1.x), then you can’t consume it in your application.
This release of .NET Standard now supports around 33K APIs, compare to 14K APIs supported by .NET Standard 1.x. The good thing is that majority of the APIs are from .NET Framework. This makes life easy to port code to .NET Standards. Below image gives you a summary of .NET Framework APIs which are now included in .NET Standard 2.0.
Now, you can use datasets, datatables, reflection and binary serialization with .NET Standard. You can find the complete list here.
This version 2.0 also fixes the third-party library compatibility issue with .NET Standard. Now you can use them with .NET Standard (Thanks to compatibility shim used by .NET Standard.). Wait, there is a catch. If there is any API used by third-party library which .NET Standard doesn’t have, then you can’t use the third-party library with .NET Standard.
How to install .NET Standard 2.0
Installing .NET Standard 2.0 is super simple. Download the installer from here and run it. Don’t worry about current SDK installed on your system. Multiple versions of SDK can be installed side by side. Navigate to “C:\Program Files\dotnet\sdk” in your machine to see list of all SDK version installed on your machine.
Once the installation is complete, open command prompt and type following command.
You should see 2.0.0-preview1-005977. Let’s create a new console application.
dotnet new console -o NetStandard2App
This should create a .NET console application. To verify the version used by this newly created application to ensure it is targeting .NET Core 2.0., Open the .csproj file in notepad and you should see
netcoreapp2.0 used as target framework.
<PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup>
You should also read this excellent post by Andrew Lock to find out how to work with diffenet version of .NET SDK simultaneously.
You can also create an ASP.NET Core 2.0 application from dotnet cli. Like,
dotnet new web -o ASPNetCore2App
You can build and run this application from dotnet cli. To open it in Visual Studio, you need to install Visual Studio 2017 Preview 3 or latest version of Visual Studio Code. Read Quick summary of what’s new in ASP.NET Core 2.0.
That’s it for now.
.NET Standard 2.0 is a major step forward for smooth transition from .NET Framework to .NET Core as it now supports majority of .NET Framework API. This post talks about what’s new with .NET Standard version 2.0 and how to install it and use it.
Thank you for reading. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.