×

Tools to Upgrade Your Existing .Net App to .NET Core/.NET 6.0

Debasis Saha  Print   7 min read  
14 May 2022
 
Intermediate
13K Views

Introduction

Today, in this article we will discuss the upgrade process of any existing .NET application into .NET Core 6. Last year November, Microsoft has been launched the updated version of the dotnet framework i.e., .NET 6. .NET 6 is one of the Long-Term support-based versions provided by Microsoft. Except for the cross-platform environment, .NET Core also provides better performance along with several enhancements over the earlier .NET Framework. Also, it is an Open source-based framework and not proprietary, as a Framework used to be. So, if we have an application that was developed into the earlier version of the .NET framework like. .NET Framework 4.5 or 4.8 or .NET Core 1.0, etc. Then we can migrate or upgrade the application into the latest .NET version i.e., .NET 6.0. So, in this article, we will discuss several aspects of the upgradation process of any application into the current .NET version.

Migrate into .Net Core 6 from Earlier .Net Core Version

In this section, we will discuss related to the migration process for any existing application which is developed in the earlier version of ASP.NET Core like 3.1 or 5.0. To upgrade any applications into the latest .NET Core version, we need to install Visual Studio 2022 with Asp.Net and Web Development workload. It is the only prerequisite related to this upgrade process. During the upgrade process, we need to follow the below instructions or steps –

  • If in our process we use a global.json file, then we need to upgrade the target .NET SDK Version.
  • {
     "sdk": {
     "version": "6.0.100"
     }
    }
    
    
  • We need to update the Project File’s Target Framework to .net6.0
  • <Project Sdk="Microsoft.NET.Sdk.Web">
     <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
     </PropertyGroup>
    </Project>
    
  • In the structure of the project, we need to update the Nuget Packages which we used. In the Nuget Package part, we need to update each Microsoft.AspNetCore.* and Microsoft.Extensions.* package reference version to 6.0.0 or higher (as per the availability).
  • <ItemGroup>
     <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="6.0.0" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
     <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
     <PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
    </ItemGroup>
    

    After the update the package, we need to delete the bin and obj folders. Also, we can run the command dotnet nuget locals –clear all to clear the Nuget package-related cache.

  • .NET 6 fully supports the existing startup.cs class and Hosting model of the earlier .Net Core versions.

Migration Tools for Upgrade Application into .Net 6/.Net Core 6

So, in this section, we will discuss related the process to migrate or porting our code from .NET Framework to the latest .NET 6.0. For any simple application-based project, porting process from the earlier .NET framework to the current .NET 6.0 is much more straightforward. But as per the complexity level of the projects, we may need to work extra after the initial migration of the project files to the latest version.  if the application already uses the app model using .NET (such as libraries, consoles, or desktop-based applications), then we usually require very little change. But if the application required a new app model like an application using Asp.Net and we want to migrate it into Asp.Net Core, then we require more works. For this type of scenario, instead of using manually porting an application into .NET 6, we can use different tools which help us to automate some aspects of work during the migration. Because porting a complex solution is always a complex process. These types of tools will help us in that process. There are several tools available for porting applications. Some of the tools are -

  1. .NET Upgrade Assistant
  2. .NET Portability Analyzer
  3. Try-Convert Tool

.NET Upgrade Assistant

The .NET Upgrade Assistant is a command-line tool that can be used for different kinds of .NET applications. This tool main developed to provide assistant during the upgrading process of any application from .NET Framework to .NET 6. After running the tool, the application always requires some additional effort to complete the migration. This tool contains the installation process of analyzers which can provide help to us while completing the migration process. Now, this tool supports the following .NET Framework-based application types –

  • .NET Framework Windows Forms apps
  • .NET Framework WPF apps
  • .NET Framework ASP.NET MVC apps
  • .NET Framework console apps
  • .NET Framework class libraries

This tool main used MSBuild to work with the project files. So, to work perfectly with this tool, it is necessary to install the latest version of MSBuild. For this purpose, we can install the latest version of Visual Studio. This tool needs to be installed with help of the .NET CLI tool. We need to run the below commands to install the tools –

dotnet tool install -g upgrade-assistant
Evolution of ASP.NET Core

If you have already installed the .NET Upgrade Assistant tools, then you can upgrade the version by using the below commands –

dotnet tool update -g upgrade-assistant
Evolution of ASP.NET Core

Now, after the installation of the tools, we need to run the tools for our existing application project to upgrade into .NET 6.0 framework. So that open the terminal and navigate to the folder where the target project or solution is located. Then run the below commands to upgrade the framework version –

upgrade-assistant upgrade .

The tool runs and shows you a list of the steps it will do and perform the upgradation process.

.NET Portability Analyzer

The .NET Portability Analyzer is a tool through which can analyze our existing projects and prepare detailed reports based on targeting .NET  Framework which components or parts are missing into the applications or libraries. The .NET Portability Analyzer is provided as a Visual Studio Extension and it can analyze one assembly per project.

To start work using the .NET Portability Analyzer in Visual Studio, we first need to download and install the extension from the Visual Studio Marketplace. Currently, it supports either Visual Studio 2017 or Visual Studio 2019. After installation, we need to configure it in Visual Studio through Analyze >Portability Analyzer Settings and select our Target Platforms, which are the .NET platforms/versions that you want to evaluate the portability gaps compared with the platform/version that your current assembly is built with.

Try-convert tool

The try-convert tool is a .NET global tool that can convert a project or entire solution to the .NET SDK, including moving desktop apps to .NET 6. However, this tool isn't recommended if your project has a complicated build process such as custom tasks, targets, or imports. This is a simple tool that will help in migrating .NET Framework projects to .NET Core.

Install it as a global tool here: dotnet tool install -g try-convert

If you already have it installed, make sure to update: dotnet tool update -g try-convert

Now, for use the tool simply navigates to the root of your solution by using normal command-prompt and simply execute:

try-convert

If you only want to convert a specific subfolder, solution, or project, type: try-convert -w path-to-folder-or-solution-or-project

Conclusion

Asp.net Core 6.0 has been released with many new features and functionality. In this article, we discuss the different migration processes of the. Net-based application from an earlier version to the latest .NET 6. Any suggestions or feedback or query related to this article are most welcome.

Share Article

Take our free skill tests to evaluate your skill!

In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.

Learn to Crack Your Technical Interview

Accept cookies & close this