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, the .NET Core 2.1 preview is out for people to try. Two days ago, the  .NET team announced the first preview of .NET Core 2.1

Let us see some of the highlights of 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.

https://www.microsoft.com/net/download/dotnet-core/ sdk-2.1.300-preview1

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

Latest stable version

After it is installed.

Installed

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.

 Application tab

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.

Package Reference

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 the dotnet -version command to check the version.

Command

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 IntelliSense.

IntelliSense

Let us create a .NET Core 2.1 application from scratch.

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

Create New Project

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

Web Application

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.

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>();

Now, open Startup.cs class.

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

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

This code is for GDRP. This is a new cookie consent feature that 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 the .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 the 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 sets the current compatibility version of MVC
  • 2 new files were added which are _CookieConsentPartial.cshtml and Privacy,cshtml which are mainly used to summarize your privacy and cookie use policy

Note. 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.