First look of Asp .Net Core 2.1 preview 1: Convert existing .Net Core application to .Net Core 2.1

NET-core-2.1-1

You can find all .Net core posts here.

Finally, .Net Core 2.1-preview is out for people to try it. Before 2 days, .Net team has announced the first preview of the .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 .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

2.1

And once it is installed:

2.12

What are some features sailed 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 that. But if you have gone through the above link for the feature overview of .Net Core 2.1, you might be knowing 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 then Properties -> Application tab -> Target framework -> select .Net Core 2.1 as below:

2.13

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 the TargetFramework should be netcoreapp2.1:

2.14

That is it. Your application is now converted to .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:

2.19

As you can see it is showing 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 Intellisence:

2.15

Let us create .Net Core 2.1 application from scratch.

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

2.16

Click on Ok and in next window, select Web Application(MVC) as shown below:

2.17

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

New method looks like this:


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

Now open Startup.cs class

In the method ConfigureServices, you will see 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 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 code added in 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

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.

You can find all .Net core posts here.

Hope it helps.

 

 

 

8 thoughts on “First look of Asp .Net Core 2.1 preview 1: Convert existing .Net Core application to .Net Core 2.1

Leave a comment