2

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?

3

3 Answers 3

3

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 without <> 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.

2
  • I did as you said and I get an error at startup dotnet: "Failed to complete because the specified command or the specified file was not found." I used: "dotnet file.cs"
    – h4cktivist
    Commented Apr 19, 2020 at 7:06
  • is dotnet run file.cs
    – Zegameus
    Commented Apr 19, 2020 at 17:49
1

https://www.mono-project.com/download/stable/#download-lin

Install mono.

And then in the console: csc 'location of a .cs file'

To run it: mono 'location of the compiled exe'

5
  • When i using csc I get an error: Syntax error: illegal atomic form: () inside expression `(string ...)'. I'm used "csc hello.cs" and get it
    – h4cktivist
    Commented Apr 18, 2020 at 16:26
  • mono-project.com/docs/getting-started/mono-basics You mean this?
    – SubSpecs
    Commented Apr 18, 2020 at 16:27
  • Yes, I mean this
    – h4cktivist
    Commented Apr 18, 2020 at 16:29
  • WinForms Hello World or Console Hello World? Which one you tried to compile?
    – SubSpecs
    Commented Apr 18, 2020 at 16:35
  • Console Hello World
    – h4cktivist
    Commented Apr 19, 2020 at 3:27
0

Consider trying an Ubuntu solution which is Mono C# Compiler

First, install the mono-mcs package:

sudo apt-get update -y
sudo apt-get install -y mono-mcs

Next, compile your C# file:

mcs yourfilename.cs

Finally, execute the compiled program:

mono yourfilename.exe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.