Blog


About Cocoa# and Xcode

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.

Ch.. Ch.. Changes....

Quoting the ever great, David Bowie, change is in the wind.  After a while working towards this 'few products, narrow focus' strategy, a fellow software developer and Mac SB guy has largely convinced me that this strategy is one that really doesn't suit my business very well, nor does it address my personal inability to stay on one project for more than a week at a time without having to 'shift gears' to stay interested.   

So how do I address that?  

Well, I think I'm going to go with a slightly different approach.  Rather than worry about 3 or 4 big projects, I'm going to start releasing the bits and pieces as smaller projects, and offer bundles when we get more of them completed.

It also means resurrecting a couple of projects that had been more or less off-lined, because there remains interest in them (and I was still working on them as time permitted).  

This week, the D56 Collection Manager will reappear on the site, and in a couple of weeks, so will the XML Editor under a new name. In addition, over the coming weeks, we will be taking the wraps off of a couple of ideas that had been percolating for a while, but nothing really became of them.   With the addition of Matt doing some work, and me offloading two of my long standing projects to another developer, the resources to make this a bigger part of my day, and my income has once again come to the forefront.

Also, keep in mind, that the gang of nerds here are always on the prowl for small contracts in application and web development for Windows or the Mac, so if you have a need, let us know.  We have representatives in both Atlanta and Seattle.

Looking to MWSF...

Well tomorrow is keynote time.  Guess the entire Mac world will grind to a halt for a couple of hours tomorrow.

Oh, and sorry about the missing link back to my old digs.  Words of a Geek is at http://web.mac.com/dru_satori.

Posts from 2007

  • General Mac & Technical Nerdery
  • Other Tidbits
  • Registration Process Choices.
  • Holidays
  • Details

Copyright Andy 'Dru' Satori, 2006-2007, All Rights Reserved