Upgrading .Net Core 3.1 to Net 5.0 Preview 6

fernandosonego

Fernando Sonego

Posted on July 13, 2020

Upgrading .Net Core 3.1 to Net 5.0 Preview 6

We are getting closer to the final release of .Net 5, the new version of this wonderful framework created by Microsoft. This new version, as we saw in other posts, is not a simple update, it is the unification of what we know with .Net Core and .Net Framework. As it is not a minor issue, Microsoft has recommended migrating all the applications that we have in previous versions to .Net Core 3.1 to this version. Considering that time is running out and that many of us have a curious soul, I leave this guide to update to .Net 5 to test our applications on the new version of the platform.

Alt text of image

As we talked, we are going to see the necessary steps to update a project to the current version of .Net 5 which is Preview 6. Before we start we must have 3 points in mind:

  1. Although this Preview is quite advanced, they may have some errors that correspond to the version, the recommendation that I can give you is to review the release notes for particular cases. Also, be patient, we will surely have a new Preview in a short time.

  2. Let's take this practice as evidence of future migrations and that the new products we will make will be of a quick update. This means that once the final version of .Net 5 is there, we should not stop there, we must start thinking about the next version.

  3. Any problem or error that we find, let's not stop reporting it to the Microsoft team, this will help make the next preview or version more solid and stable. Also, if we find any recommendation and opinion. The team that carries out this framework is open to all the feedback we can give you.

The first thing to do is download the latest available version of .Net 5. You can download it from the following link dotnet5 . Once downloaded we will proceed to install it. We will see the image screen, we just have to follow the steps.

Alt text of image

To correctly verify the version, we will open the Windows console and execute the command dotnet --info.

Alt text of image

The next thing will be to install the Preview version of Visual Studio 2019 that is currently in version 16.7 Preview 3.1, you can download it from this link https://docs.microsoft.com/en-us/visualstudio/releases/2019/release -notes-preview . In my case I will use the professional version, but you can choose any version you want.

In the installation steps we will only choose that we want to install the development tools "Asp.Net and Web development".

Alt text of image

We will create a solution with 3 types of projects: Web MVC Razor, Web API and Test Unit that we will use to do the update process.

The Web project and WebApi are using .Net Core 3.1, they are based on the MVC model. This base template will have the drivers for defaults that come in the templates, for example, in the WebApi project, we will have a driver that returns weather information.

In both projects we must update the csproj file with the new version. To be able to do it we must select the project, right click, "Edit Project File".

Alt text of image

Both projects will have the same configuration. We can see the code here:

<Project Sdk = "Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework> netcoreapp3.1 </TargetFramework>
  </PropertyGroup>
</Project>

We must modify the “TargetFramework” tag from netcoreapp3.1 to netcoreapp5.0, remaining as follows:

<Project Sdk = "Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework> netcoreapp5.0 </TargetFramework>
  </PropertyGroup>
</Project>

It is quite simple, then we compile the application to see that it updates the packages and verify that everything is correct.

It may be that some more updates are necessary if we are using some references such as EntityFramework or some additional third-party package. The recommended steps to update are as follows:

  1. Update "Microsoft.AspNetCore" to the latest version.
  2. Update "Microsoft.EntityFrameworCore" to the latest version.
  3. If we have some third party dependencies in our project, it is a good time to update those dependencies.

Once these steps are ready, we are all ready to compile the projects. We will run each of the applications to verify that everything is correct.

Finally, we have the unit testing project. Although the csproj may look a little different, we will follow the same steps that we used in the previous projects, we will modify the csproj. Before modifying it looks like this:

<Project Sdk = "Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework> netcoreapp3.1 </TargetFramework>
    <IsPackable> false </IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include = "Microsoft.NET.Test.Sdk" Version = "16.5.0" />
    <PackageReference Include = "MSTest.TestAdapter" Version = "2.1.0" />
    <PackageReference Include = "MSTest.TestFramework" Version = "2.1.0" />
    <PackageReference Include = "coverlet.collector" Version = "1.2.0" />
  </ItemGroup>
</Project>

Modified as follows:

<Project Sdk = "Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework> net5.0 </TargetFramework>
    <IsPackable> false </IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include = "Microsoft.NET.Test.Sdk" Version = "16.6.1" />
    <PackageReference Include = "MSTest.TestAdapter" Version = "2.1.1" />
    <PackageReference Include = "MSTest.TestFramework" Version = "2.1.1" />
    <PackageReference Include = "coverlet.collector" Version = "1.3.0" />
  </ItemGroup>
</Project>

We will also need to update the Microsoft.Net.Test.SDK reference. Build and everything ready.

conclusion

In this post we saw how in a fast and easy way we could transform our applications in .Net Core 3.1 to Net 5. Please, keep in mind that this is a preliminary version, in no way should we put these versions in productive environments. If it is recommended, test the migration of our current applications to the new versions of .Net. In future posts we will continue to see the news provided by the new versions of .net 5.

💖 💪 🙅 🚩
fernandosonego
Fernando Sonego

Posted on July 13, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related