First Look At ASP.NET Core 2.1 Preview One - Convert Existing .NET Core Application To .NET Core 2.1

.Net Core

You can find all my .NET Core posts here.

Finally, .NET Core 2.1 preview is out for people to try. Two days ago, the  .NET team has announced the first preview of .NET Core 2.1

Let us see some of the highlights for this release.

How to download .NET Core 2.1?

You can download the latest stable version, i.e., .NET Core 2.1.300-preview1, from here.

Choose as per your operating system and it should install .Net Core 2.1.300-preview.

.Net Core

After it is installed.

.Net Core

What are some features included with ASP.NET Core 2.1?

I have written a detailed post on the features of ASP.NET Core 2.1 which you can find here.

Many awesome features are there.

How to convert your existing .NET Core application to .NET Core 2.1?

You might be wondering why should you do this. But if you have gone through the above link for the feature overview of .NET Core 2.1, you might know the powerful features coming with .NET Core 2.1. For example – SignalR, HttpClientFactory, Https, GDRP and many more.

If you have downloaded the .NET Core 2.1, then it is very easy to convert your application into .NET Core 2.1.

Let us convert my SSL sample from here into .NET Core 2.1.

Open the application -> Right-click and go to Properties -> Application tab -> Target framework -> select .NET Core 2.1 as below.

.Net Core

Build your application.

Open the .csproj file and change the version for the PackageReference to 2.1.0-preview1-final as shown below. Also, make sure that the TargetFramework should be netcoreapp2.1.

.Net Core

That is it. Your application is now converted into .NET Core 2.1.

How to make sure .NET Core 2.1 is available?

Below is what I do to check.

Write dotnet -version command to check the version.

.Net Core

As you can see it is showing the correct version.

One quick step to check if the application is converted to .NET Core 2.1 is to check whether you can see SignalR support because SignalR is sailed with .NET Core 2.1.

Open Startup.cs class and in Configure method, write app.UseSignalR.

If .NET Core 2.1 is installed correctly, then you should see that in the intelliSense.

.Net Core

Let us create .NET Core 2.1 application from scratch.

Open your Visual Studio 2017 -> Create New Project -> Select Core Web application.

.Net Core

Click on Ok and in the next window, select Web Application (MVC).

.Net Core

What is changed in the default code and structure?

Once the application is created, open Program.cs class, you will some changes here.

  • BuildWebHost is changed to CreateWebHostBuilder
  • The return type of the method CreateWebHostBuilder is changed to IWebHostBuilder – along with other changes

The new method looks like this.

  1. public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>  
  2. WebHost.CreateDefaultBuilder(args)  
  3. .UseStartup();  

Now, open Startup.cs class.

In the method ConfigureServices, you will see the below code,

  1. services.Configure < CookiePolicyOptions > (options =>   
  2. {  
  3.     // This lambda determines whether user consent for non-essential cookies is needed for a given request.  
  4.     options.CheckConsentNeeded = context => true;  
  5.     options.MinimumSameSitePolicy = SameSiteMode.None;  
  6. });  

This code is for GDRP. This is a new cookie consent feature which will allow you to ask for (and track) consent from your users for storing personal information.

Apart from this, by default HSTS is added with .NET Core 2.1 application, I have written a post on the same which you can find here.

So below are some default codes added to the Startup.cs class.

  • app.UseHsts(); is added by default for HSTS support
  • app.UseCookiePolicy(); is also added by default and it enables cookie policy capabilities
  • app.UseHttpsRedirection(); is also added by default which is used to redirect HTTP to HTTPS. More details here
  • services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) is also added by default which is setting the current compatibility version of MVC
  • 2 new files added which are _CookieConsentPartial.cshtml and Privacy,cshtml which are mainly used to summarize your privacy and cookie use policy


Please have a look here regarding all the details for the improvements of HTTPS with .NET Core 2.1 preview 1 and to run your application for the first time securely with HTTPS.

I hope it helps.