Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating .NET Framework 4.6.2 to .NET Standard 2.0 [closed]

We have a set of class libraries which are created under.NET Framework 4.6.2, we want to move these libraries into .NET Core 2.0 or .NET Standard 2.0

We have the following ways,

  • Create a new project and copy over the code.
  • Convert your existing project by editing the CSPROJ file.

Which one is better to migrate the libraries and will .NET Standard impact on performance over the the .NET core.

Is there any alternatives to migrate these collections.

like image 217
SRINIVASREDDY VELPULA Avatar asked Oct 13 '18 09:10

SRINIVASREDDY VELPULA


2 Answers

I think there might be a misunderstanding of what .NET Standard 2.0 actually is.

.NET Standard was created to create a common API surface across multiple different implementations of .NET.

Those implementations include .NET Framework, Mono, .NET Core and more. In that sense - .NET Core is a version of .NET, there is no connection between .NET Standard and .NET Core.

If you create a .NET Standard library it is basically platform agnostic, meaning it can run on any implementation of .NET that supports the version of .NET Standard you are targeting. This means if you upgrade an existing .NET Framework 4.6.2 library to .NET Standard, you are only getting portability of the library, but if you still use the library in an app targeting .NET Framework, you will see no performance gains as the library will still run against the same .NET Framework.

If you ported your whole app itself to .NET Core (which will be even easier when 3.0 is out), you would definitely see the performance gains, as your library will then run on .NET Core.

As for porting - it is usually easiest to just create an empty library and manually copy the existing classes to the new library and then install all required NuGet packages.

like image 121
Martin Zikmund Avatar answered Sep 19 '22 06:09

Martin Zikmund


Adding to @Martin's answer, to migrate your existing .NET Framework application to .NET Core, you can first start with portablility analyzer tool. This tool is a Visual Studio extension and gives a detailed report on how flexible your application is.

Migration your existing project to .NET Core is a journey and it can take some time depending on the nature of your solution. This tool is quite useful in determining the state of your project. If you are only targeting .NET framework 4.6.2, the migration should be relatively straightforward. Here is what you could do:

  1. Create new .NET SDK Style project enter image description here

  2. Edit the csproj file of new project and change the target framework to net462.

<PropertyGroup> <TargetFramework>net462</TargetFramework> </PropertyGroup>

  1. Move your files from old project to new project.

  2. Delete your old project and update the references

  3. Repeat step for all the class libraries

I would suggest to start with a class library with minimum dependencies, test the changes and move to more complex ones once you have converted all the simple ones.

like image 25
Ankit Vijay Avatar answered Sep 19 '22 06:09

Ankit Vijay