How to Write Programs in C# .Net, to Run Them on Linux/Wine/Mono

How to write programs in C# .NET, to run them on Linux/Wine/Mono?

Have you read about Mono.NET on http://www.mono-project.com?

It allows you to write .NET apps for Linux with minor differences over the Microsoft implementation.
I don't think wine will cope with any of the .NET components.

Just read the documentation before and you have a go.

PS: This also gives you the compatibility list between mono and .NET. http://www.mono-project.com/Compatibility and MoMA(mono migration analyzer) is a tool that will scan any .NET app already created to see if its compatible to deploy on linux.

Using C# System.Diagnostics.Process under Wine on Linux

This is due to limitations of Wine that won't be fixed.

While Windows processes running under Wine can start native processes, they cannot wait for a native process or interact with it via pipes once it is started.

There are plenty of ways around this, but they all involve some work on your part. You could, for example:

  • Use a Windows build of the programs you need to use (probably not an option, I take it).
  • Use a .sh script that executes the program you want and redirects the input/output using files.
  • Write a winelib program that acts as a proxy for the native Linux process, funneling information between the Wine and Linux pipes.
  • Use a Windows ssh client to run Linux programs on localhost.

Ways to run compiled .exe from .Net Framework in Linux

Answer is this:

sudo apt-get install mono-runtime
sudo apt-get install libmono-SYSTEM*
sudo apt-get update
mono application.exe

This will run my application. Probably if someone else got other things than winforms, other packages could be needed.

Porting ASP.NET application to Mono/Apache under Linux

I run an ASP.NET 4.0 application on Suse Linux using mono. My experience with mono is that it just works. My app is ~ 15.000 LOC and uses third party components like mongo-csharp-driver, lucene.net, elmah, munq, and sphorium.webdavserver.

I've had almost no compatibility problems during development - and the ones I had where easily worked out (for example sphorium accesses the registry; this obviously works different on Linux/Mono). I've even started developing with Visual Studio instaed of MonoDevelop and without the Mono plugin, because Visual Studio is a better IDE, and it just works when I compile my web app on linux and deploy it on Apache (even though I develop with .NET on Windows).

I've written a short blogpost on getting started with the setup

How to use LuaInterface on Mono/Linux

LuaInterface looks to be pure C#, but it uses a mixed mode C++/CLI-ified version of the Windows version of the native Lua library, that mixes .NEt code and native 32-bit Windows code. There's no C++/CLI compiler for platforms other than Windows, so you can't port/recompile the C++/CLI code, though it should work on Mono on Win32 (or maybe Wine)..

The only really viable way to get this to work on Mono would be to make it use P/Invokes istead of C++/CLI. You could then use a dllmap so that when Mono tries to resolve the P/Invoke calls to lua51.dll, it is redirected to the Linux equivalent, liblua.so.5.1.

can any ASP.net app (or most of them) be made to run under Linux using Mono?

The answer to 'can any (or most of) the ASP.NET apps be made to run' is YES. There's a page with some common pitfalls: Mono: Porting ASP.NET Applications (also of interest the Porting WinForms applications page)

The most common problems I've seen in the field[1] are, by number of occurrences:

  • Code that is not aware of case-sensitive filesystems or careless about file/path handling. These ones require work.
  • P/Invokes: there are a lot of P/Invokes to Windows native functions. Most of them are not supported in Mono (nor they make sense in a unix environment). However, we have mappings for a few or the most common ones (CloseHandle and such). These ones require redoing the same things using a .NET API.
  • Bugs: believe or not, there are still bugs in the 3M+ lines of code. We try to be responsive and fix bugs as soon as possible (and we'd love to do more, blame it on the 24h rotation period). The simpler the test case to reproduce the problem, the faster it gets fixed. File a bug report and we'll try to fix it ASAP.
  • Missing or unimplemented APIs: we still have these and try to focus on the most used ones. Some times we use the Moma Reports (see link below) to prioritize.

Take a look at the Moma Reports page, which contains user-submitted data about applications on which Moma has been run.

[1]: the field ranges from one of the largest ASP.NET deployments in the Western Hemisphere to small open source applicatoins.

Mono .NET and C# features

The Mono C# compiler is considered feature complete for C# 1.0, C# 2.0 and C# 3.0 (ECMA). A preview of C# 4.0 is distributed with Mono 2.6, and a complete C# 4.0 implementation is available with Mono 2.8 or when building Mono from our trunk source code release.

http://www.mono-project.com/CSharp_Compiler

Also, checking this thread can be helpful:

The Limitation of Mono Runtime



Related Topics



Leave a reply



Submit