Compiling MonoGame Linux programs on the command line

Download and unzip the minigame source files

Unpack the MonoGame DLLs to the sources directory

  1. Download MonoGame for MonoDevelop or MonoGame for Xamarin Studio.
  2. Unpack the DLLs and *.config files from assemblies/Linux/ into the colorsquare/ sources directory. Note: mpack files are zip archives.

Total size: < 5 MB

apt-get install

apt-get install libmono-system-drawing4.0-cil mono-dmcs libopenal1 libsdl1.2debian libsdl-mixer1.2

Total size: approx. 16 MB for Mono, 0.5 MB for OpenAL, and 7.5 MB for SDL and SDL_mixer (on a slim Ubuntu Precise, with X.Org already installed)

cd into the sources directory on the command line

cd colorsquare

Compile the C# sources

dmcs -r:MonoGame.Framework.dll -target:winexe -out:colorsquare.exe *.cs

Run

mono colorsquare.exe

Hints

Use the mcs compiler in Mono ≥ 2.11

If you choose to compile Mono from source, note that starting with Mono version 2.11 a new unified compiler mcs is available. It replaces all previous runtime specific compilers. When using one of these recent versions, the compile command for the example sources (C# 4.0) is:

mcs -sdk:4 -r:MonoGame.Framework.dll -target:winexe -out:colorsquare.exe *.cs

DllNotFoundException or TypeLoadException

If you hit a DllNotFoundException or TypeLoadException, double-check that you have installed all the required media libraries (SDL, SDL_mixer, and OpenAL) and copied all the MonoGame DLL and *.config files to the same directory as colorsquare.exe. If you're still having trouble, you can read more about what the config files do (http://www.mono-project.com/DllNotFoundException), and then try running with more debugging information:

MONO_LOG_LEVEL=debug mono colorsquare.exe

The particularly tricky cases are when a DLL fails to load because one of the DLLs on which it depends can't be found. For example, if OpenTK.dll is missing, the error message might look like:

Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
  at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0

But setting MONO_LOG_LEVEL=debug exposes the real problem (OpenTK could not be loaded):

Mono: Assembly Loader probing location: '/colorsquare/OpenTK.exe'.
Mono: Assembly Loader probing location: '/usr/lib/OpenTK.exe'.
Mono: The following assembly referenced from /colorsquare/MonoGame.Framework.dll could not be loaded:
     Assembly: OpenTK (assemblyref_index=2)
     Version: 1.1.0.0
     Public Key: bad199fe84eb3df4
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/colorsquare/).

MonoGame DLLs placed in a subdirectory

If you move the MonoGame DLLs to a subdirectory, you will need to tell mono where to find them.

MONO_PATH=/path/to/MonoGameLibs/ mono colorsquare.exe

Found a mistake?

Submit a comment or correction

Links

Guidelines:Application Deployment
Recommendations on how to package Mono applications for the best end-user experience. In particular, note that the easiest way to include unstable libraries is to keep them in the application binary folder. Placing unstable libraries in the Global Assembly Cache is not appropriate.
Command-line Building With csc.exe
Working with the C# 2.0 Command Line Compiler

Updates

29 Jun 2013 Posted