Friday, June 26, 2015

Compiling and Running using Mono


Hi All,

Following are a basic set of "mono" commands that allows to run .NET code. These commands ran on MAC OS X.

Compiling code to an EXE

Here we are going to compile a C# code using "mcs" command that comes with Mono. Lets say we have the following code with the name of the file being "hello.cs".

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

To compile the code to an EXE, run the following command.

mcs hello.cs

Running the above command would create an a file named "hello.exe". To execute the "hello.exe", run the following command.

mono hello.exe

The above should print the output as "Hello Mono World".

Now lets say there is an external DLL dependency file which is needed to compile the program successfully. To do so, run the following command.

mcs hello.cs -r:My.Reference.dll



No comments:

Post a Comment