Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile C# based Windows (WinForms App) application to run on Mac OS High Sierra or Mojave

Tags:

c#

windows

macos

I have built an (Windows Forms App) application on Windows in C#. Now, I would like to target this whole project / application to mac OS without changing the application. Is there any easy way to achieve it? I don't want to rebuild the entire app from scratch on MAC. I don't want to use virtual machine on MAC... I have Visual Stuido 2017 and a paired MAC. But, I'm lost here.

like image 620
ThomAce Avatar asked Nov 25 '18 10:11

ThomAce


1 Answers

;TLDR Mono, using WinForms and MonoDevelop IDE for development.

.NET Framework is the full implementation that includes everything but runs only on Windows.

.NET Core is the newer OpenSource implementation of .Net framework but doesn't include WPF/WinForms - because those rely heavily on DirectX/GDI essentially making them Windows only.

Xamarin. Xamarin based off of Mono framework branched more towards iOS and Android. There is a Xamarin Mac but it supports the same GTK# based UI toolkit as Mono.There is a WinForms equivalent UI toolkit as well called Xamarin Forms but it is mobile only (iOS, Android & Universal Windows Platform)

Mono. Mono is OpenSource implementation of .Net framework, uses GTK# by default for UI. Does run fine on all of Windows, Linux, macOS. Uses GTK# as underlying UI toolkit on all OSes including Windows.

What's Cross Platform? There is a subset of Base Class Library, called .NET Standard Library - as well as the compilers platform, only these subsets of .Net are truly cross-platform.

To sum it up, Mono does however support Windows Forms on both Linux & macOS. Except some corner cases it works very well. However the UI look and feel is Windows only. It is like running Windows applications under WINE. Default Mono IDE is MonoDevelop.

Xamarin Mac is great if you want to write a new application from scratch since Xamarin Mac exposes you full macOS SDK and offers its own IDE (Xamarin Studio).

In your situation though, Mono is best option. After having installed mono you can even try running your current app as mono appName from terminal. It should render the UI even if the paths and other resources are broken.

Update 2021

WPF and WinForms now are open source and part of .Net Core (which now is referred to as .Net. Core is dropped in name). The previous classic .Net is now called .Net framework. New WPF/WinForms features enhancements are on available for .Net only. Though these still are Windows only and will stay so.

Avalonia UI Framework and Uno Platform are newer .Net Core (AKA .Net) based cross-platform solutions. Both use XAML. Avalonia is more like WPF while Uno tries to be cross-platform UWP.

like image 175
Abdullah Leghari Avatar answered Oct 09 '22 23:10

Abdullah Leghari