views:

627

answers:

4

Hi,

I have the following questions:

  1. Is it possible to compile a C# project using VS.NET, and run it on mono?
  2. Are there any performance benefits associated with approach 1 (vs compiling with the mono compiler)?
  3. What about running the output .exe/.dll on linux? And what are the associated performance characteristics?

Thanks

+5  A: 
  1. Yes, you can do that. It should work unless the code uses some framework elements that are not implemented on mono.

  2. Not that I am aware of.

  3. Not sure what the difference between #3 and #1 is. If you are referring to using mono to compile on Windows, then porting it to linux, it should still work the same. Both compilers generate essentially the same IL code.

palehorse
A: 

I don't know about the performance but this article attempts to show how to compile the MonoDevelop tool under vs. This should give you some idea as to what the differences will be.

Preet Sangha
+4  A: 

1:
Yes. The compilers compile into IL code, which runs in either system.

Not every library is implemented in Mono, but those that are should work seamlessly. Also, the code has to be written to be independend of the system to work properly, for example:

  • Use Path.DirectorySeparatorChar and Path.Combine to form file paths, instead of using the string literal "\" or "/".
  • Use the BitConverter class to do byte manipulation that is independend of big-endian / little-endian achitecture.

2:
There may be some differences in what code the compilers generate, but as almost all optimising is done by the JIT compiler that should rarely make any measurable difference.

3:
The exe and dll files does not contain native code, they contain IL code. The native code is generated by the JIT compiler when the exe/dll is loaded.

Guffa
I think the EXE/DLL contain CLR loader/binders.
jameszhao00
+1  A: 

To expand on others answers:

For point 3. Yes there will be a performance difference when using MSCLR vs Mono, and no, I don't know what it will be. Maybe nothing, maybe little or perhaps one is vastly faster - you'll have to profile your specific application.

Note also, that notwithstanding the speed of the code made by the JIT compiler, the libraries will be implemented very differently and will almost certainly have varying performance characteristics.

If you plan on supporting your application under Mono, you will need to run performance testing there as well as MS CLR.

MarkR