How do I compile a Windows.Forms application on Linux for .NET Core?

Viewed 15468

I can compile my application on Linux using mono mcs, but the result is an executable for .NET Framework 4.5. On windows it runs but I cannot use any newer functionality.

I tried to find out how to compile it with .NET SDK 5.0 but on Linux it seems to not include Windows Forms.

Is there a way to compile a forms application on Linux which uses at least .NET Core 2.0?

3 Answers

Windows Forms (and WPF) are both not supported on Linux with .NET Core and probably never will be. Winforms runs on mono, but that is based on .NET Framework, not .NET Core. The reason is mostly because the internal implementation of Windows Forms is actually an abstraction layer over the Windows GDI, and therefore a linux port would need to be a complete rewrite.

.NET 6.0 will bring a new GUI framework called maui, which is intended to bring real cross-platform experience to .NET. This is hopefully the last step to make .NET really cross platform, as it was actually designed 20 years ago. You can already try it out, as prerelease versions of .NET 6.0 are ready for download (go to https://aka.ms/dotnet-download).

You can develop WinForms and WPF UI applications using .Net Core. But these UI applications can run only on Windows. Only non-UI applications developed in .net core is truly cross-platform and can run on Windows, Linux and Mac OS.

The MAUI framework is yet to be officially released from Microsoft that allows UI applications to be cross-platform.

MAUI

If you switch from Windows Forms to UWP you can target the Windows, macOS and Linux platforms (as well as mobile) with a single visual studio solution. You just need to use the Uno platform https://platform.uno/

Related