It’s been twenty years for the reason that .NET framework first appeared. Since April 2019, it has been frozen at .NET Framework 4.8, and .NET (previously .NET Core) has changed it.
Beginning with .NET Framework 4.5.2, Microsoft introduced that .NET Framework can be tied to the lifecycle of the OS. For Home windows 10, meaning its lifecycle will finish in October 2025. Nevertheless, Home windows 11 contains .NET Framework 4.8, so there’s no rush to leap to .NET 6.
In the event you’re growing software program in C#, you’ve got a selection: Must you stick with .NET Framework or transfer to .NET?
Two Situations to Think about
State of affairs One: Internet Work: All of the innovation and enhancements are actually in .NET. That is the place you’ll discover Blazor, SignalR, Microservices and ASP.NET Core. Nevertheless, the variations are pretty minor, as .NET Core (the precursor to .NET) has been round for fairly some time, and the improve assistant instrument will do the conversion. With all that in thoughts, let’s transfer on to:
State of affairs Two: Desktop Work: Each WinForms and WPF can run on .NET, although solely on Home windows, not Linux or Mac. You probably have an current .NET Framework utility that you simply want to run on .NET, then it can want changing utilizing a Microsoft-provided improve assistant (extra on that later). Console functions work properly on Linux and Mac.
One other distinction is the variations of C#. Newer variations of C# are solely showing in .NET, with the newest being C# 11 (at the moment in Preview), whereas .NET Framework 4.8 is completely caught at C# 7.3. It’s attainable to put in C# 8.0 on .NET Framework (as this Stack Overflow query explains) however there are some new options akin to new nullable attributes that aren’t supported.
WinForms on .NET
Over time I’ve developed fairly a couple of WinForms functions; in concept, they need to additionally work in .NET. Nevertheless, I’ve discovered the designer is one thing of a piece in progress and infrequently takes a really very long time to open. It has been utterly redesigned in .NET 6, as this Microsoft weblog put up explains. It doesn’t really feel fairly as snappy because the designer on .NET Framework.
As a part of this text, I created a easy type in a .NET Framework challenge and the identical in .NET 6, each utilizing probably the most up-to-date Visible Studio 2022 on Home windows 11.
In case your WinForms utility does any quantity of graphics processing, it’s seemingly that it makes use of System.Drawing. This supplies entry to the Home windows GDI+ graphics performance. In the event you begin growing for Linux with .NET, you’ll discover that the System namespace not incorporates Drawing. This was one of many breaking modifications introduced within the notes for .NET 6 (you may examine it).
Strive operating an utility utilizing System.Drawing on Linux or Mac and also you’ll get this exception: “System.Drawing.Frequent just isn’t supported on non-Home windows platforms.” There’s a configuration swap that allows you to cover this exception on .NET 6 however it will likely be eliminated in .NET 7. Microsoft suggests you turn libraries to one in all ImageSharp, SkiaSharp or Microsoft.MAUI.Graphics.
I transformed an utility to make use of SkiaSharp to generate a Bitmap picture in RAM after which reserve it to disk as a .png file. It ran with no points on each Home windows and Linux (Ubuntu 22.04); however altering libraries is sort of a ache and can take a couple of days or even weeks to do. There’s no simple conversion, because the graphics code needs to be rewritten.
This can be a free command line instrument created by Microsoft for upgrading .NET Framework tasks to .NET 6. It not solely handles WinForms and WPF tasks but in addition UWP tasks, console functions, ASP.NET MVC web sites and .NET Framework class libraries. It really works for each C# and VB.NET tasks. A tutorial concerning the improve assistant has been offered by Microsoft.
As soon as put in you may analyze or improve the challenge. Doing the analyze command produces a .sarif formatted file. That is quick for Static Evaluation Outcomes Interchange Format. There’s a free Sarif viewer out there right here for Visible Studio and an extension for VS Studio Code. It outputs this:
[20:11:27 INF] Operating analyzers on WinFormsAppFramework
[20:11:28 INF] Recognized 0 diagnostics in challenge WinFormsAppFramework
[20:11:28 WRN] HighDpiMode must set in Most important() as an alternative of app.config or app.manifest – Software.SetHighDpiMode(HighDpiMode.<setting>). It’s endorsed to make use of SystemAware because the HighDpiMode choice for higher outcomes.
[20:11:28 INF] Evaluation Full, the report is offered at …(snipped).
Operating the assistant with improve shows a collection of steps, beginning with backing up the challenge. Then it’s a matter of simply urgent 1 to do the subsequent step or 2 to cancel it. When my challenge was transformed, the one distinction I observed in code was that the Most important() methodology had the next name added:
It compiled and ran with out points.
Having to improve with the assistant implies that it’s in all probability one thing you’ll do solely when you really want to, notably if it makes use of System.Drawing. I’ve a sense that loads of WinForms and WPF software program will stay on .NET Framework for some years to come back. The advantages of having the ability to construct functions for Linux and Mac gained’t occur if it makes use of WinForms/WPF for UI.
In the event you want to develop a GUI C# utility for Linux or Mac, then you definately’ll want an alternate library. There are a number of round (Uno, Avalonia and others), so discover what works for you.