Convert .Net Framework 4.6.2 project to .Net core project

Convert .Net Framework 4.6.2 project to .Net core project

This appears to be an official Microsoft resource for doing the migration. Summarized below:

  1. (recommended) Retarget all projects you wish to port to target the .NET Framework 4.7.2 or higher.

  2. (recommended) Use the .NET Portability Analyzer to analyze your assemblies and see if theyre portable to .NET Core.

  3. (recommended) Install the .NET API analyzer into your projects to identify APIs throwing PlatformNotSupportedException on some platforms and some other potential compatibility issues.

  4. Convert all of your packages.config dependencies to the PackageReference format with the conversion tool in Visual Studio.

  5. Create new projects for .NET Core and copy over source files, or attempt to convert your existing project file with a tool.

  6. Port your test code.

Most of BCL is still the same API-wise, so conversion is definitely viable for consideration. Yes, there may be incompatibilities in your code (or more often – with your dependencies) and the easiest way to check is to try building it with .net core.

For more details about when to convert (and when to rewrite) or about options of performing the conversion you could follow this guide: Upgrading to .NET Core and .NET Standard Made Easy.

Convert .Net Framework 4.6.2 project to .Net core project

The easiest way to switch a .net framework project to a .netcore project is to open the csproj file and change the TargetFramework from something like this

<TargetFramework>net462</TargetFramework>

to something like this

<TargetFramework>netcoreapp3.1</TargetFramework>

You could also change it to .net standard, in case you want compatibility between .net core and .net framework consumer projects, by changing it to this:

<TargetFramework>netstandard2.0</TargetFramework>

You could target multiple frameworks like so:

<TargetFrameworks>net462;netstandard2.0</TargetFrameworks> 

Ensure you use the correct version number and obviously depending on what this project already targets, things are going to break and will need fixing. For example, you cant use a .net framework class library with a .net core project.

A more detailed process is provided here:
https://docs.microsoft.com/en-us/dotnet/core/porting/

Leave a Reply

Your email address will not be published.