Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build a C# file through Mono on Linux command line?

Tags:

c#

linux

mono

I wrote a simple Hello World program in C# using Visual Studio 2013. I tried to compile it on the command line in Linux using:

mono --aot test.cs

However when I do that, I get the error:

Cannot open assembly 'test.cs': File does not contain a valid CIL image.

The file is just a typical C# console application using the default template that Visual Studio gives you.

like image 543
Generalkidd Avatar asked Dec 02 '13 21:12

Generalkidd


Video Answer


1 Answers

You should use gmcs in order to compile your code, and mono to execute the interpreter, as one use javac and java commands.

You may reread the mono basics:

Let's say you have a C# file with the following code:

using System;

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

}

Compiling within the shell:

gmcs hello.cs

Executing it from the shell:

mono hello.exe
like image 112
0x90 Avatar answered Oct 16 '22 17:10

0x90