24

I need a way to cross compile a short piece of .NET C# code to a dll, which will then run a client's Windows environment.

I run OS X 10.9.2 on an iMac.

Does anyone know what tools allow this?

I would rather not install Parallels and Windows if I can find a way to cross compile this without needing that heavy of an installation of Microsoft tools.

6 Answers 6

22

Check out the Mono Project. It may be what you are looking for.

http://www.mono-project.com/Mono:OSX

MonoDevelop is a cross-platform IDE primarily designed for C# and other .NET languages. MonoDevelop enables developers to quickly write desktop and ASP.NET Web applications on Linux, Windows and Mac OSX. MonoDevelop makes it easy for developers to port .NET applications created with Visual Studio to Linux and Mac OSX maintaining a single code base for all platforms.

8
  • monodevelop.com MonoDevelop is a cross-platform IDE primarily designed for C# and other .NET languages. MonoDevelop enables developers to quickly write desktop and ASP.NET Web applications on Linux, Windows and Mac OSX. MonoDevelop makes it easy for developers to port .NET applications created with Visual Studio to Linux and Mac OSX maintaining a single code base for all platforms. -- If you can't compile your code correctly with MonoDevelop, they you may have no choice but to run a VM.
    – level42
    May 2, 2014 at 15:37
  • Thx, I've been looking at Mono, but while it should work, I've found no clear "how to" either install or use it.
    – Jagra
    May 2, 2014 at 15:54
  • 1
    @Jagra There are a few tutorial videos here: youtube.com/results?search_query=monodevelop+install+mac
    – level42
    May 2, 2014 at 15:56
  • 1
    Just to iron out any doubt: Yes, if you compile a DLL on Mono, it will run on Windows without any modification whatsoever, given that you don't use any specific Mono libraries, such as Mono.Addin or Mono.Simd. It goes both ways, too - a DLL/EXE compiled on Visual Studio will run unmodifed on Mono, given that you don't use any specific Microsoft/Windows libraries such as WPF, Workflow Foundation, COM+ etc. May 2, 2014 at 23:38
  • 1
    @Jagra: Once you install Mono (and MonoDevelop if you want it) from go-mono.com/mono-downloads/download.html, it's very easy to use. Even without MonoDevelop, you should be able to compile most .sln projects straight from Visual Studio, using xbuild.
    – Jwosty
    May 3, 2014 at 3:20
13

You can install it with homebrew:

brew install mono

Then you can use it with:

mcs hello.cs
mono hello.exe
8

If you have a Mac you can compile C# like this:

Compile: mcs fileName.cs
Run: mono fileName.exe

If you don't have Mono installed on your Mac, you can google it and install it and then you will be good to go. You don't need Windows to do this.

2

No personal experience with this IDE but this looks like it will work: http://monodevelop.com

2

You may now want to look into the following

Xamarin https://www.xamarin.com/

Visual Studio for Mac https://www.visualstudio.com/vs/visual-studio-mac/

2

Can I compile .NET C# code on my Mac?

You can compile C# code yes.

I would rather not install Parallels and Windows if I can find a way to cross compile this without needing that heavy of an installation of Microsoft tools.

Mono does not have 100% compatibility with the .NET implementation.

The Common Language Infrastructure (CLI) is a framework for executing managed code. The CLI consists of several parts including a Virtual Execution System (VES). .NET's VES is the Common language Runtime. Mono has it's own separate VES implementation.

In other words, at the very least do not expect to run code that has only been tested in a *nix/OSX environment to run without testing it on a windows environment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .