- Saved searches
- Use saved searches to filter your results more quickly
- License
- DanielVanNoord/System.Windows.Forms
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- how to install and use Winforms in VSCode on Linux?
- 1 Answer 1
- Running Windows Forms on Linux with Mono
- Step 1 — Install Mono
- Step 2 — Create an Application
- Step 3 — Compile and Run
- Taking it Further
- Comments
- About Mark Heath
- Search this site
- Keep Updated
- My Pluralsight Courses
- My Open Source Software
- Archives
- Tags
- How do I compile a Windows.Forms application on Linux for .NET Core?
- 4 Answers 4
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A .Net Core implementation of System.Windows.Forms based on Mono’s System.Windows.Forms for Linux and Windows
License
DanielVanNoord/System.Windows.Forms
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
System.Windows.Forms for .Net Core running on Windows and Linux
This is a early stage and experimental port of Mono’s System.Windows.Forms and a few additional libraries to .Net Core 3.1. This allows Winforms code to run on both Windows and Linux (and possibly MacOS in the future).
Rather then porting Mono’s implementation of System.Drawing to .Net Core 3.1 I ported Mono’s System.Windows.Forms onto System.Drawing.Common. Note that on Linux you will need some native libraries.
Even though this is highly experimental and unsupported it does work (at least for me).
A Demo on my Raspberry Pi 4, built and running on the Pi using .Net Core 3.1.
Linux — Several native libraries, at least libx11 (libx11-dev on Ubuntu) and libgdiplus (libgdiplus on Ubuntu)
Mac — Not currently working. The Mono code that this is based on was 32 bit only. .Net Core requires 64 bit so until that is done this will not work.
There are three samples: SimpleTest (which uses my .Net Core Winforms), SimpleTest.NetCore (which uses the official .Net Core Winforms) and SimpleTest.NetFX which uses Net Framework. This also shows how to use the same source code with all three different platforms as the code is added as a link to the NetCore and NetFX projects. This way you can use the officially supported and nice looking Winforms on Windows.
To test this on Linux simply dotnet run in the SimpleTest folder.
More samples are coming soon TM. This will include more complex forms and more demonstrations of using the different libraries for different platforms.
I tested the SimpleTest example on Windows, Raspbian Buster and Ubuntu 20.04 using .Net Core 3.1 Release.
Unknown right now. I will likely add more samples and fix issues as I go. If Mono adds support for Mac 64 bit I will port that over.
I will add better Linux documentation as I have time.
The Mono code is under the MIT license (https://github.com/mono/mono/blob/master/LICENSE). My contributions are under the MIT license as well.
About
A .Net Core implementation of System.Windows.Forms based on Mono’s System.Windows.Forms for Linux and Windows
how to install and use Winforms in VSCode on Linux?
(.NET Core Version 3.0.103 (Commit: b7ef045669), Platform/OS: ubuntu linux 18.04-x64, Winforms branch version (date): Thu Mar 26 07:37:13 2020 -0700, VSCode 1.43.2) I cloned current version of Winforms from Github, tried to use appropriate installation script (build.sh) but finally got only error message (I think it’s a bug). Possibly someone was more succefull? (Even though Winforms Designer doesn’t still work in VSCode on Linux as I got from documentation there should be possibility to create Windows Form Application templates from console, port existing application from .NET Framework to .NET Core and so on). So can anyone share your experience about this?
1 Answer 1
Winforms is currently a Windows-only technology in the .NET Core runtime. I haven’t seen an instance of someone circumvening this limitation.
.NET Core (and in the future .NET 5 that is built on top of .NET Core) will be the future of .NET. We are committed to support .NET Framework for years to come, however it will not be receiving any new features, those will only be added to .NET Core (and eventually .NET 5). To improve Windows desktop stacks and enable .NET desktop developers to benefit from all the updates of the future, we brought Windows Forms and WPF to .NET Core. They will still remain Windows-only technologies because there are tightly coupled dependencies to Windows APIs. But .NET Core, besides being cross-platform, has many other features that can enhance desktop applications.
The Mono Project supports Winforms, which can be run on linux, however I’m unaware of how to develop Winforms via Mono on vscode.
Running Windows Forms on Linux with Mono
Although WinForms may be “dead”, it does have one trick up its sleeve that WPF doesn’t, and that is you can run WinForms apps on mono. Here’s a simple guide to running a Windows Forms application on Ubuntu
Step 1 — Install Mono
Open a terminal window, and make sure everything is up to date with the following commands:
Now you can install mono with the following command:
Step 2 — Create an Application
Now we need to create our C# source file. You can use any text editor you like, but if like me you aren’t familiar with Linux text editors like vi or emacs, gedit is a simple notepad-like application which is easy to use. Launch it with the following command: (the ampersand at the end tells the terminal not to wait for gedit to close before letting us continue)
Now let’s create a very simple application:
Step 3 — Compile and Run
Now we’re ready to compile. The C# compiler in mono is gmcs. We’ll need to tell it we’re referencing the Windows Forms DLL:
To run the application, simply call mono, passing in the executable:
And that’s all there is to it! We have a WinForms app running on Linux.
Although mono doesn’t support everything in WinForms, you can use most standard controls, so you can easily add further UI elements:
Taking it Further
Obviously writing applications by hand like this is a bit cumbersome, but there is an IDE you can use for Linux called monodevelop. You install it like this:
This then gives you a nice editing environment, allowing you to debug, and manage project references (you’d usually add System.Windows.Forms and System.Drawing). Unfortunately it doesn’t offer a WinForms designer – for desktop apps it prefers you to use GTK#. Nevertheless, it’s a nice free IDE allowing you to experiment with getting your existing Windows Forms applications working cross-platform on Linux. (It seems this will also work on OS X with mono installed but I don’t have a Mac so I haven’t tried it out)
Want to learn more about Windows Forms? Be sure to check out my Pluralsight course Windows Forms Best Practices.
Comments
Can I run an existing application developed using deveX gui components?
That will be great if I can do that.
About Mark Heath
I’m a Microsoft MVP and software developer based in Southampton, England, currently working as a Software Architect for NICE Systems. I create courses for Pluralsight and am the author of several open source libraries. I currently specialize in architecting Azure based systems and audio programming. You can find me on:
Search this site
Keep Updated
My Pluralsight Courses
- Microservices Fundamentals
- LINQ Best Practices
- Microsoft Azure Developer: Deploying and Managing Containers
- Azure Functions Fundamentals
- Azure Durable Functions Fundamentals
- Microservices Architecture: Executive Briefing
- Building Microservices
- Dapr 1 Fundamentals
- Create Serverless Functions
- More Effective LINQ
- Versioning and Evolving Microservices in ASP.NET Core
- Microsoft Azure Developer: Implement Azure Functions (AZ-204)
- Azure Container Instances: Getting Started
- Building Serverless Applications in Azure
- Azure CLI: Getting Started
- Understanding and Eliminating Technical Debt
- Windows Forms Best Practices
- Digital Audio Fundamentals
- UWP Audio Fundamentals
- Audio Programming with NAudio
- Understanding Distributed Version Control Systems
- Creating Modern WPF Applications with MahApps.Metro
- Creating and Selling a Digital Product
- ClickOnce Deployment Fundamentals
My Open Source Software
- NAudio
- NLayer
- NAudio.Sharp Media Foundation
- WaveForm Renderer
- WPF WaveForm
- TypeScript Tetris
- Skype Voice Changer
- MIDI File Mapper
- MIDI File Splitter
- SilverNibbles
- Asterisk
- WPF Shapes
- .NET Voice Recorder
Archives
Tags
- Azure (150)
- NAudio (100)
- Advent of Code (81)
- LINQ (79)
- F# (70)
- Azure Functions (67)
- C# (63)
- Azure CLI (45)
- WPF (39)
- audio (38)
- XAML (38)
- JavaScript (36)
- Silverlight (34)
- Pluralsight (27)
- Docker (26)
- MoreLINQ (26)
- Durable Functions (25)
- Azure Blob Storage (20)
- Azure Service Bus (17)
- Azure Container Instances (15)
How do I compile a Windows.Forms application on Linux for .NET Core?
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?
Microsoft explicitly stated its attitude not to support WinForms apps on Linux (Just like Apple doesn’t support Swift iOS development outside macOS), github.com/dotnet/winforms So grab a Windows machine please, and don’t waste your time on Mono WinForms.
4 Answers 4
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).
It provides valuable insights, but some issues 1) Mono does not have a complete WPF story, so «They run on mono» is not accurate. 2) «a linux port would need to be a complete rewrite» is true, but the reason was that Microsoft WinForms was not open sourced. 3) MAUI won’t come from Microsoft with Linux support, github.com/dotnet/maui/discussions/339 but requires the community to create and support that.
@LexLi Right, that was to simplistic. With «from Microsoft» I meant «supported by Microsoft». The whole open-source implementation of dotnet core is still maintained by Microsoft employees. So also for the now open-source implementation of WinForms, it’s Microsoft that gives the final sign-off on whatever changes get merged. And they said that they (at least for now) would not accept any PRs that provide a linux port.
WinForms is relatively simple, and had few changes over a decade, and there already is (although buggy) Linux WinForms code for .NET Framework. Would it be that difficult for a few talented people to implement WinForms on .NET Core? I had high hopes when I first heard about MAUI, but after seeing how it is just a big clunky complicated mess to run mobile apps on desktop suboptimally, I gave it up. Again, MAUI does not seem like a desktop GUI framework like WinForms/WPF, but more like a mobile GUI framework that happens to be able to run on Windows.
@DamnVegetables I agree that it would probably be possible to get that to work, however it will be hard to get a broad community without support from MS. I haven’t had the chance to look into Maui, but since it looks as it’s the only framework that will evolve, I do believe people will see these deficiencies and fix them. Of course, having no official linux support (as of now) is also not helping.