Search code examples
c#compilation

How can I compile C# code on Linux terminal?


I'm starting learning C#, but I have no idea how I can compile my code using terminal. I searched the internet, but nothing helped me. I'm tryed to use gmcs and csc and nothing helped. So, how can I compile C# file using linux terminal?


Solution

  • To compile a C# file, you need to have dotnet installed, here is a link with the info on how to install it. Dotnet Then you go to where the file is and put:

    dotnet run <file.cs>
    

    (without <> obviously).

    Although it is highly recommended that you create a project first and paste your code into the Program.cs file. This way you will avoid unnecessary headaches.