Reputation: 71
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?
Upvotes: 1
Views: 8002
Reputation: 56
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.
Upvotes: 3
Reputation: 53
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
Upvotes: 0
Reputation: 57
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'
Upvotes: 1