So a few years ago, I was working on some .net / C# code and I wanted to do so on the Mac. At the time, Mono was just getting started, and it's Mac support was weak, at best. For a while I was involved and actively trying to get Mono and the Mac to play well. Eventually, I hit burn out. Things weren't going quickly, I lacked the talent to fill in the gaps, and didn't get along particularly well with one of the core dev's. Eventually, I stopped actively working in the community, and though up until about 2 months ago I hosted the web page for the Cocoa# project, my level of activity was fairly low.
These days, I'm more of a casual user, I have some C# codebase that I continue to maintain and test on Mono, but the state of Cocoa#, Mono and .Net on the Mac in general really hasn't progressed much further than it was when I left a year or so ago. The compiler works very well, the run-time for command line applications is very good, and if you are willing to work at it, you can use Mono's Forms implementation to create simple GUIs. The debugger doesn't work, the IDE is MonoDevelop and though it runs on the Mac, it's still basically a Gnome application and few Mac users will ever be comfortable in it.
Could Mono be more? Yes, absolutely, but Apple needs to help by publishing the plugin interfaces required to wire it into Xcode, and someone needs to fund Novell's efforts to get the debugger working. These things won't happen unless something changes in the landscape, and soon. That is not to say that Mono is unusable today.
Today, I'm going to show how to build a 'Hello World' application in Xcode using Mono.
First we'll start with Create a New Empty Project for the HelloWorld.Net project. In Xcode, select the File, New Project menu items. In the new Project window, select Empty project, hit Next and then fill in the name and folder. Next we need to create three empty files in the project. Select the File, New File menu item and then choose the Empty File in project option. Name it Makefile. Repeat this for files named AssemblyInfo.cs and another named HelloWorld.cs. Next Create a new Target for the Makefile.
At this point Xcode is all ready for you to start editing files. There are three for you edit. First, we need the Makefile to tell Xcode how to build the project. While this is a very simple Makefile, it will serve the needs of most simple console projects.
SHELL = /bin/sh
srcdir = .
top_srcdir = .
DESTDIR =
all:
mkdir -p ./bin
mcs -out:./bin/HelloWorld.exe -target:exe \
-lib:./bin/ \
-reference:System.dll \
AssemblyInfo.cs \
HelloWorld.cs
clean:
rm -rf ./bin/*
install:
echo not implemented
Next is the AssemblyInfo.cs, I will not include the content here as it is boilerplate that you can create once and never edit again if you choose. The boilerplate is in the associated download of the project as seen at the top of the page.
Finally is the HelloWorld.cs file, it is short sweet and too the point.
using System;
public class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello World!");
}
}
With all of these entered, you are ready to build (hit the build button in Xcode). The resulting file, HelloWorld.exe will be in the projects 'bin' directory. Open Terminal, CD to the projects bin directory and run the result using 'mono HelloWorld.exe'. If all went well, you have a working exe that will also run anywhere you have a .NET runtime.
What this doesn't get you is any of Xcode's bells and whistles, it is just a simple text editor and project manager. At one point I had working templates for Exe and Library projects as well as syntax templates for CS that worked to a point in Xcode, but all of that was broken in 2.5. If time (or interest) permits, I'll update them, but in truth, these days I tend to focus on getting paid so I can feed my family, and well, free software that doesn't generate revenue (my PostgreSQL work generates some consulting revenue) doesn't help accomplish that goal.
