简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM