Improvements in .NET Core 2.0
Last year, Microsoft launched the .NET Core 2.0, .NET Standard 2.0 and ASP.NET Core 2.0 with the purpose to bring a common .Net platform everywhere. In this article, we will talk about the improvements that have been made in .NET Core 2.0 and why these are important for developers to get their apps run on different environments.
.NET Core 2.0 provides performance improvements in the runtime and framework. It adds support for .NET to six new platforms that include Debian Stretch, SUSE Linux Enterprise Server 12 SP2 and macOS High Sierra. Let’s look at the improvements made in .NET Core 2.0 in detail:
Mainly there are improvements in the below areas
- Language support
- Platform Improvements
- API changes
- Visual Studio Integration
dotnet restore runs implicitly
If we are using Visual studio code / CLI tool and using .NET Core 1.x, we have to run the ‘dotnet restore’ command explicitly to download dependencies after creating a new project and whenever we added a new dependency to project.
In .NET Core 2.0, we don’t have to run ‘dotnet restore’ command because it’s run implicitly by commands such as ‘dotnet build’ and ‘dotnet run’.
Retargeting to .Net 2.0
If the .NET Core 2.0 SDK is installed, then projects that target .NET Core 1.x can be retargeted to .NET Core 2.0.
To retarget to .NET Core 2.0, edit project file (*.csproj / *.vbproj) and change the Target Framework as below
.NET core 2.0 in addition to supporting C# and F#, also supports Visual Basic 2017. You can use Visual Basic to create the following project types.
- .NET Core console apps
- .NET Core class libraries
- .NET Standard class libraries
- .NET Core unit test projects
- .NET Core xUnit test projects
.NET Core 2.0 supports C# 7.1 which adds a number of features like:
- The Main () method, application entry point can be marked with ’async’ keyword.
- Default literal expressions
- Inferred tuple element names
For more details on C# 7.1 click here.
.NET Core 2.0 includes number of features that make it easier to use on Linux and macOS
- .NET Core 2.0 offers a single Linux implementation that works on multiple Linux distributions. In case of .NET Core 1.x we need to download Linux distribution specific implementation, as shown below:
- You can also develop apps that target Linux as a single operating system. .NET Core 1.x requires that you target each Linux distribution separately.
- .NET Core 1.x on macOS requires the OpenSSL toolkit's cryptographic library. .NET Core 2.0 uses the Apple cryptographic libraries and doesn't require OpenSSL.
API changes and library support
.NET Core 1.x supports the .NET Standard version 1.6; .NET Core 2.0 supports the latest version, .NET Standard 2.0. .NET implementation support matrix is as shown below. For more details on .NET standard click here.
.NET Standard 2.0 includes over 20,000 more APIs than were available in the .NET Standard 1.6. Much of this expanded surface area results from incorporating APIs that are common to the .NET Framework and Xamarin into .NET Standard.
.NET Standard 2.0 class libraries can also reference .NET Framework class libraries, if they call APIs that are present in the .NET Standard 2.0. No recompilation of the .NET Framework libraries is required.
The total number of APIs available on .NET Core 2.0 has more than doubled in comparison with .NET Core 1.1.
.NET Core code can reference existing .NET Framework libraries, including existing NuGet packages. Note that the libraries must use APIs that are found in .NET Standard.
Visual Studio integration
Previously Visual studio and .NET Core were tightly coupled, but now you can install .NET Core SDK independently of Visual Studio. This makes it possible for a single version of Visual Studio to build projects that target different versions of .NET Core.
If you are building a project for multiple target frameworks, you can select the target platform in Visual Studio from top-level menu.
.NET Core 2.0 supports Live Unit Testing. Previously, Live Unit Testing was available only for .NET Framework applications.
These improvements have been brought about to make .NET Core more developer friendly and make more of the APIs consistent across the different versions of .NET.
If you would like to know more about .NET Core 2.0, please contact us.
Manjunath Govindappa | ASP.NET Technical Lead