Mandy's Tech Blog

Sitting in relative obscurity since 2007…

View My GitHub Profile

Follow me on Twitter

Come work with me!

Site feed

Developing for .NET on the Mac, Part 1: Building Mono for the First Time

Update: the process for building Mono has changed significantly since I first wrote this. You can view updated instructions here.

Ever since I first heard about Mono, I've been fascinated by the potential of .NET to become a viable platform for software that targets multiple OSes. Unfortunately, I've discovered (as seems to be the case with many OSS projects), the documentation aimed towards beginners is quite limited, especially when one ventures away from running Mono on Linux.

I've spent many hours trying to get my development environment for the Mac just right, and at times, it's been a rather painful process. So, in the interest of reducing the pain felt by any beginners following after me, I've decided to start recording my processes for getting things set up. At best, this blog will become a useful resource for anyone doing .NET development on the Mac. At worst...well, at least I'll be able to set things up again the next time I have to wipe a hard drive or replace a machine.

One of the first things that I've found in my work is that the Mono installer available from the Mono Project is rarely sufficient for doing any serious development work: bugs abound in the new parts of Mono (I've found a number of problems in generics), and sometimes, I simply can't resist the urge to dig in and fix them. Therefore, when setting up a new development environment, my first goal is generally to get a custom build of Mono up and running.

Here's how I do it:


The actual work:

  1. Create a folder for your mono source. For the purpose of these instructions, I'll assume you're going to put it in ~/src/mono.
  2. Open a Terminal window and go to ~/src/mono. Run the command svn checkout svn:// svn:// This will download the code for the core Mono libraries and the Mono Compiler System. They'll end up in ~/src/mono/mono and ~/src/mono/mcs.
  3. Create a folder into which you can install your custom build. I put mine in /opt/mono.
  4. Run the command cd ~/src/mono/mono && ./ —prefix=/opt/mono. This step should get Mono ready to build.
  5. You're now ready to build and install: make && make install. I'd love to be able to recommend that you also insert make check in that list, but the sad fact is that Mono on MacOS actually fails a number of tests.

After you've done all this, you should have a working (custom) build of Mono working on your machine. You can, at any time, upgrade to the latest code by going to ~/src/mono and running the command svn update mono mcs. Generally, you'll be able to jump straight to building Mono again, but you may sometimes be required to also run

Also, it's often very handy to have a script around that will set up all of your paths and whatnot to your custom build of mono. The Parallel Mono Environments page on the Mono website describes this, although I had to modify mine a bit to get it working right. Here's what it looks like now:

export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include:/sw/include:/Library/Frameworks/Mono.framework/Versions/
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig:/sw/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/X11R6/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/
PS1="[mono] \w @ "

Mine is stored in ~/mono-dev-env and is invoked via source ~/mono-dev-env

That's it for my first post on setting up a development environment for Mac/.NET development. In the future, I'll go into setting up mod_mono (for ASP.NET), CruiseControl.NET (you do have unit test you'd like to run regularly, don't you?), and Subversion (I realize that Subversion isn't strictly related to .NET, but I didn't have a Subversion server when I started this project, and trying to figure out how to get it set up wasn't terribly fun).

comments powered by Disqus