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?
-
may this help you? legendminds.in/how-to-run-net-core-console-app-on-linuxNajiMakhoul– NajiMakhoul2020-04-18 15:27:25 +00:00Commented Apr 18, 2020 at 15:27
-
No, i have no command "dotnet" and I can't install it with "apt install dotnet"h4cktivist– h4cktivist2020-04-18 15:58:30 +00:00Commented Apr 18, 2020 at 15:58
-
Have a look at how to install .net sdk via linux package managers.weichch– weichch2020-04-19 05:26:04 +00:00Commented Apr 19, 2020 at 5:26
3 Answers
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.
3 Comments
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 Comments
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