.NET Core - Is there a way to implement WinForms?
Edit: Since I wrote this back in September 2017, the reality has changed. As of the .NET Core SDK 3, Windows Forms support has been added back in. It does not have the platform independance of many other parts of .NET Core and converting between .NET Framework and .NET Core WinForms code needs a conversion tool. But it is there.
No, not really. .NET Core is a specific selection of classes from the larger .NET Framework, which includes Windows Forms. Windows Forms is one of the things they (had to) cut out to make the smaller .NET Core.
Last I looked, .NET Core had support for UWP (a followup to WPF), Xamarin and ASP.Net 5 (Core version). UWP and maybe Xamarin would be suitable for Desktop applications:
- Frameworks, Programming for .NET, Display technologies and the like
Building a WinForms C# application with Docker .NET Core image results to an error : .NETFramework,Version=v4.6.1 were not found
TLDR: You cant build a Desktop app for Linux by using only the .NET stuff from Microsoft. Your alternatives are Mono or a third party UI stack.
You cannot build a WinForms application on Linux with .NET Framework or .NET Core. To uderstand this you must understand the .NET ecosystem:
Runtimes
.NET Framework is Windows only, and it's done. Do not expect much change on .NET Framework. To build you application on .NET Framework you are forced to use Windows
.NET Core is the fairly new cross platform .NET that can run almost on everywhere. While .NET Core is cross-platform, WPF and WinForms still are Windows only.
Mono is an alternative open-source implementation of .NET Framework, Mono includes a WinForms implementation but as @Frank Alvaro said already YMMV.
UI Frameworks
.NET Core supports building Desktop Applications since version 3.0 but only on Windows. Both UI Frameworks, WinForms (Windows Forms) and WPF (Windows Presentaion Foundation) are more or less wrappers around Windows API and currently Microsoft does not seem to be interested in making them cross-platform. So sadly no official WinForms or WPF for Linux.
There are some third party alternatives for .NET Core for example: Avalonia or GtkSharp.
Unable to find Windows Forms App (.NET Core) Template. Where is it located?
- There are two branches of .NET: Framework and "new" .NET/.NET Core.
- In the dialogs shown, all items are repeated twice. One of those items has " (.NET Framework)" appended to its description, the other has nothing extra.
- By deductive logic then, of the two items shown, the one for .NET/.NET Core is the one that is not for .NET Framework.
And indeed, if you select the plain-Jane "Windows Forms App", the wizard prompts you to select a framework from a dropdown that only includes .NET/.NET Core frameworks.
Compiling C# code with Windows Forms in Linux
If you're not using the latest version of Mono, this should work:
gmcs -pkg:dotnet *.cs
The latest version of mono uses mcs
instead of gmcs
. In the previous ones, mcs
targets .NET 1.1.
Related Topics
Ef Core Returns Null Relations Until Direct Access
Line Delimited Json Serializing and De-Serializing
Catch Multiple Exceptions At Once
Could Not Establish Trust Relationship For Ssl/Tls Secure Channel - Soap
Converting String to Byte Array in C#
C# Getting the Path of %Appdata%
Best Timer For Using in a Windows Service
Understanding Covariant and Contravariant Interfaces in C#
Insert 2 Million Rows into SQL Server Quickly
How to Export Datatable to Excel
Ado.Net |Datadirectory| Where Is This Documented
Convert Json String to C# Object
Why Does the Ef 6 Tutorial Use Asynchronous Calls
How to Update an Observablecollection Via a Worker Thread
How to Get the Current Username in .Net Using C#
Difference Between Covariance & Contra-Variance