Running Mono 3.0.5 Beta on Windows

Mono is a really cool concept. It’s a C# compiler/framework that works cross-platform. C# is fantastic, so I really like the idea of being able to develop C# (potentially with Visual Studio) and target any device. Until Mono came along, C# was only used on Windows because it uses the Microsoft .NET framework. (Mono also boasts the MonoGame platform and the MonoDevelop IDE for Linux coding.)

image

Here is the introduction from the Mono Wikipedia page:

Mono is a free and open source project led by Xamarin (formerly by Novell and originally by Ximian) to create an Ecma standard compliant .NET Framework-compatible set of tools including, among others, a C# compiler and a Common Language Runtime.

The stated purpose of Mono is not only to be able to run Microsoft .NET applications cross-platform, but also to bring better development tools to Linux developers.[3] Mono can be run on many software systems including Android (and most other Linux distributions), BSD, iOS, OS X,Windows, Solaris, and some for game consoles such as PlayStation 3, Wii, and Xbox 360.”

So I downloaded Mono to try it out on Windows (I’ll try Ubuntu next) and I ran into an issue right away. Just trying to validate the install using the “Hello World” example on the Mono Basics page didn’t work. It’s really not that complicated, here’s the example program:

using System;
 
public class HelloWorld
{
    static public void Main ()
    {
        Console.WriteLine ("Hello Mono World");
    }
 
}

However, I couldn’t get it to work using the gmcs compiler that’s used in the example. The result was this all too common error:

C:\Mono\Mono-3.0.5>gmcs
'gmcs' is not recognized as an internal or external command, operable program or batch file.

image
This error will occur on Windows when the program actually doesn’t exist, or it can’t be discovered from the location that the console is running. There are two way to fix this issue for any Windows program:

1. Use the full path to the program and use quotes if the path has spaces in it

2. Add the path for the program to the Windows Environment Variable called “Path.”

So I tried to find the executable for gmcs, but I could not even find gmcs.bat or gmcs.exe. In this case, it wasn’t an issue with Windows or Mono, it was simply out of date documentation on the Mono site.

I received this helpful advice from the Mono user community forum, “Have you tried "mcs -sdk:2"? Mono 2.11 merged all the compilers into the one unified compiler, and now gmcs is a shell script that simply calls mcs (at least on Linux).” Ah, that’s good to know!

Here is the working version of the “basics” test code:

C:\Windows\System32>mcs --about
The Mono C# compiler is Copyright 2001-2011, Novell, Inc.
The compiler source code is released under the terms of the
MIT X11 or GNU GPL licenses
For more information on Mono, visit the project Web site
  
http://www.mono-project.com
The
compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto

C:\Windows\System32>cd C:\Mono\Mono-3.0.5

C:\Mono\Mono-3.0.5>mcs helloworld.cs

C:\Mono\Mono-3.0.5>mono helloworld.exe
Hello Mono World

image

Success!