Running/Migrating a WPF application into Linux
We have developed a WPF application that is widely used by users who have the Windows operating system on their machines. Now, we would like to also reach users who use Linux.
What would be the best approach for such a migration?
I did a little research and found these following options:
Option 1: .NET Core 3.0’s support for WPF, a WPF application can run on Linux under Wine. Wine is a compatibility layer which allows Windows applications on Linux and other OSes, including .NET Core Windows applications.
I’ve discovered this possibility by reading the following article:
https://ccifra.github.io/PortingWPFAppsToLinux/Overview.html
When I showed this solution to my team members, they claimed that according to their past experience, Wine has some major performance pitfalls. Should I test it out or it’s indeed not recommended for such a migration, according to your experience?
Option 2: I’ve also read about .NET MAUI, via this article on Microsoft blogs:
https://devblogs.microsoft.com/dotnet/introducing-net-multi-platform-app-ui/
I’m really not sure if .NET MAUI supports Linux, as the article only mentioned the Android, iOS, macOS, and Windows operating systems.
Is it possible to use it for migrating a WPF app into Linux?
If the options I’ve suggested are not great, what other options I might have for doing such a migration?
Thank you for your help and I’m looking forward to your reply,
Dima
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
Can i compile .net Core 3 WPF application in Linux?
WPF support was added in .net Core 3.0 Can i compile wpf application on Linux or in Linux-based docker container?
Compile, probably. Test? Most likely not, unless you ensure most of the testable code stays out of the WPF app and doesn’t depend on anything Windows-specific. You could test this if you have WSL enabled on a Windows machine
@dymanoid the question asks if compilation is possible. You can compile for Ubuntu on windows by using the correct runtime identifier
You can run msbuild on a Linux server in a container which is windows — I’ve used CI tooling that way in the past.
I haven’t tried, but I doubt you can install and use the Microsoft.NET.Sdk.WindowsDesktop that is required to build WPF apps on .NET Core 3 on any other platform than Windows. If you run a Windows container, it will probably work though.
2 Answers 2
You can’t — I just tried this in WSL2. The WPF templates appear in if you type dotnet new but the result of
fails in the restore step
The template "WPF Application" was created successfully. Processing post-creation actions. Running 'dotnet restore' on wpftest/wpftest.csproj. /usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(59,5): error NETSDK1100: Windows is required to build Windows desktop applications.
This error is thrown by the SDK’s targets file itself so conditional compilation won’t help. The error is thrown before compilation starts.
A good idea would be to split the project in two, a «headless» library that can be compiled, reused and tested in any OS and a UI library that can be built on Window.
Is WPF on Linux (already) possible?
I love programming with .NET, especially C# 3.0, .NET 3.5 and WPF. But what I especially like is that with Mono .NET is really platform-independent. Now I heard about the Olive Project in Mono. I couldn’t find some kind of Beta. Does it already work? Have any of you made any experiences with it? Edit: I know about Moonlight. But I want a standalone WPF application. And because of Moonlight I hope WPF on Linux will become true.
9 Answers 9
You’ll have better luck working with Moonlight, which targets the Silverlight API, which is a subset of full WPF.
edit: Sure, Silverlight isn’t «intended» for the desktop, but there’s no reason why you can’t embed a silverlight engine in your application. It’s been done before, such as for the Mac NY Times Reader
Moonlight is up to Silverlight 1.0 now. And they’ve got a slick installer for it (there’s a video of the Linux Moonlight install out there, maybe on Tim Heuer’s blog).
Update: Since people keep upvoting this, I want to point out it is long since out of date. Mono got acquired by MS years ago, and their posture regarding open-source has changed, so consider this post obsolete. (As obsolete as the WPF framework itself, heh).
Mono is in a bit of an uncomfortable position when it comes to Microsoft APIs such as Winforms and WPF. A subset of the .Net technology is an ECMA standard, but free implementations of these APIs are probably on shakier legal ground. I believe this was a large factor in the covenant between Novell and Microsoft, which is good for Novell customers. But people who use Mono that aren’t customers of Novell aren’t protected. For this reason a lot of people in the F/OSS community look askance at Mono despite its technical merits.
For this reason, Gtk# will always be preferred, since it is truly Free. Many people consider it to be superior to Winforms anyway. As far as WPF is concerned, it will almost certainly be a low priority for Novell. They may implement it eventually, but I would expect Moonlight to be the closest you could get for the forseeable future.
Since posting this, Microsoft has extended their covenant to anybody who implements the ECMA 334 & 335 standards.
Wpf application on linux
Hi everyone,
We have built a medium size application in WPF application. Now we need to run that application in Linux. Is there anyway to run this application on Linux with minimum changes?
Md. Nazmul Ahsan DIT, IADCS , CIS
Answers
Hi Nazmul, Unfortunately, there is only Mono project implements the .Net framework in Linux platform, so it can not implement WPF in linux without this project. But I know one project Wine which can allow run Windows application in the Linux. Please refer to this link: http://appdb.winehq.org/objectManager.php?sClass=category&iId=6&sAction=view&sTitle=Browse+Applications Wine supports .Net framework in Linux. You could try this. Sincerely, Jarrey Best day, Best life
Would be interesting to know. But as WPF is strongly interacting with DirectX I somehow doubt that this will work. Going the Silverlight way would be probably the most feasible way to go here. Ok, some codechanges probably — but you dont need to rewrite the whole application. But even Moonlight is more or less in the state of SL 2.0 which is kind of old. Some features of SL3 are there already but not production code quality. It seems they will try to go in the direction of SL 4.0 but that will take some time. What you can do is to embedd Moonlight somehow to mimic WPF. That will run out of browser (like in SP4) then. But that more or less a hack I’ve heard from (not tested, just was mentioned on dotNetRocks podcast). Getting something as sophisticated as WPF running under Linux would be really great. But thats a really huge effort — MS spent ALOT of money on that — and Linux has not even DirectX. I would throw Java (Swing) out immediately if I could use WPF 🙂 ————————- I Love Windows Phone http://modernappdesign.blogspot.com/