How to easily convert .NET Framework projects to the latest version

  •   Posted in:
  • .NET

And just for perspective, we have 824 C# projects and when someone thinks about converting, they may believe that they need to convert all these projects to support .NET X (where X >= 5), change the build system, etc.

It turns out that there is an easy way to do and it allows us to do proof of concept very quickly and then test compatibility. And to do this you need to do nothing. Yep, you heard me right. Our application is a native application that loads .NET Framework runtime and then loads .NET Framework assemblies.

It turns out that all we need to do is to change the .NET Framework loader to load .NET 6 runtime. It is described here. And that’s it, no more changes are required. .NET 6 runtimes loading .NET Framework 4.8 assemblies and they do not require any changes unless they call API that simply is missing in .NET 6.

No need to convert projects to a  .NET SDK style project, no need to change the build system or any other changes. Of course, if your executable is a .NET Project you need to change it to SDK style but you still can reference any .NET Framework project. And for converting I can recommend a free upgrade-assistant tool from Microsoft.

The only drawback is that because most projects stayed as .NET Framework, you cannot debug them by setting the main executable because Visual Studio will try to use the .NET Framework debugger instead of CoreClr. But you can attach VS to an app after you start it manually. Or you can add .NET 6 Class Library and make it a startup item and set Build Dependencies (right click and select Build Dependencies).

This trick can greatly help you to create a proof of concept, test compatibility with the latest .NET versions, detect areas that need attention, and save you a lot of time.

I hope it helps someone.