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-linux– NajiMakhoulCommented Apr 18, 2020 at 15:27
-
No, i have no command "dotnet" and I can't install it with "apt install dotnet"– h4cktivistCommented Apr 18, 2020 at 15:58
-
Have a look at how to install .net sdk via linux package managers.– weichchCommented 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 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.
-
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" Commented Apr 19, 2020 at 7:06
-
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'
-
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 Commented Apr 18, 2020 at 16:26
-
mono-project.com/docs/getting-started/mono-basics You mean this?– SubSpecsCommented Apr 18, 2020 at 16:27
-
-
WinForms Hello World or Console Hello World? Which one you tried to compile?– SubSpecsCommented Apr 18, 2020 at 16:35
-
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