views:

203

answers:

4

What is normally to be done to run a WinForms application on a Mac or Linux machine?

a. Just copy and run (assuming they have a Framework installed).
b. Rebuild.
c. Cosmetic source code modifications.
d. Heavy source code modifications and forms redesign.

Assuming that the application is developed as 100% managed C# 3 code by means Visual C# Express or Visual Studio 2008 targeting .Net Framework 3.5, developed without using any 3-rd party components/libraries, without encapsulating nonmanaged code or any low-level hacks - only standard Microsoft-documented .Net Framework C# API used). Or the same conditions but C# 4 language, .Net Framework 4 and Visual Studio 2010.

Is there somewhere a practical guide for developing Mono-ready applications while using MS .Net Framework and Visual Studio? Any guidelines, tips, specific aspect highlights, informing a developer of what he really needs to keep in mind to write an easily portable application without having to lookup every function in the Mono reference while coding in Visual Studio.

+10  A: 

It is possible that your app will just run with zero modifications, but I've yet to see that happen in the real world.

A tool which may help you a great deal is MoMA. MoMA is made by the same folks who make Mono, and will tell you if you are using any features that have not yet been ported.

In general, .NET 3.5 and Winforms is mostly OK. Compatibility with version 4 is still very much in development.

andypaxo
(You can get more details at http://www.mono-project.com/Compatibility)
andypaxo
"It is possible that your app will just run with zero modifications" - I can hardly believe in this as an application built and running on a Windows machine is a windows EXE file (unlike to Java whic's JAR files are not platform-specific). Do you mean a .Net EXE is meant to run on Mac or Linux with Mono installed without Wine?
Ivan
@Ivan Yes, a .NET executable is not a normal Windows binary, it's a file containing code which runs in a virtual machine (the CLR), very much like Java.
andypaxo
@Ivan: I believe there is a small stub of Windows-specific executable code that just bootstraps into CLR execution, but most of the data in a .NET EXE file is MSIL, not x86 machine language. Mono just skips over the bootstrapping code and reads the MSIL, so it's completely compatible.
Daniel Pryden
@Daniel: On newer versions of Windows, the bootstrap isn't even run; the executable loader will detect if it's a .NET EXE and pass it straight over to the CLR. Would be nice if WINE did the same but with Mono.However, there are mixed-mode executables which have both MSIL and platform-specific code. Those wouldn't be usable off of Windows, but fortunately they are rare anyway.
Chris Charabaruk
MoMA is not a silver bullet. You still need to test your application on the target OS. I fired several bug reports to Mono regarding my application passed MoMA, but failed on the target OS. Many APIs are implemented, but they may not match .NET behavior or they throw exceptions at you.
Lex Li
@Lex True, well said. There's no substitute for actually seeing your app run.
andypaxo
+4  A: 

If it's a Windows Forms application, using standard Windows Forms controls, and no 3rd party components, you can typically run this on Mono directly, just by doing a copy and run.

Mono supports Windows Forms and C# 3 features very well.

However, if you use any native components, data access outside of what is supported by Mono, or WPF, you'll run into issues. C# 4/.NET 4 will most likely not work at this point, either.

Reed Copsey
I still experience something wrong with resx and libgdiplus. :) Luckily they can be worked around.
Lex Li
A: 

Theoretical, .Net is fully cross platform, as it doesn't depend on specific architecture, but on a VM.

In practice though, you have the microsoft implementation for windows, and the mono implementation for linux/mac. The main problem is that the implementations can differ from each other, making it hard to run an application on multiple machines out of the box.

Source code shouldn't have to be altered, if not some of the libraries are not ported to mono, or different libraries are used.

C# 4 can be a bit harder, because mono isn't yet up-to-date to the microsoft implementation.

Ikke
Thing is, Mono does _a lot_ of testing against Microsoft.NET, including, if I'm not mistaken, duplicating implementation quirks where MS.NET differs from the ECMA CLR standards. Where incompatibilities between the two CLR implementations arise are generally anything brand new in Microsoft's, or incomplete work in Mono's.
Chris Charabaruk
+1  A: 

Well, i didn't develop large projects, but from my experience you would have to introduce some minor modifications to your code, but just to refine some things. The application itself should run just fine without recompilation. As for windows forms, i found it to be extremely slow some times when working with GDi, but maybe i was just doing something wrong. However, the Mono team claims it has full support of windows forms.

One more thing worth to mention. It is really hard to write a cross-platform application, which wont be harsh without using some native OS features. I think you should always consider a possibility to write some additional OS-specific modules to provide a tight integration with the underlying OS and leverage some cool stuff (like an awesome toolbar features in OSX). You should also remember, that people are used to different look&feel on different OS's

n535