C# command line tools

The csc command is used to compile C# source code files from the command line. csc stands for "C# Compiler." When you execute the csc command with the appropriate parameters and specify the C# source code file(s), the compiler compiles the code and generates an executable (.exe) file.

The compilation process involves the following steps:

  1. Command Line: Open the command prompt or terminal and navigate to the directory where the C# source code file is located.
  2. Compile: Run the csc command followed by the name of the C# source code file(s) you want to compile. For example:
csc Program.cs
  1. Compilation: The C# compiler reads the source code file(s), checks for any syntax errors or other issues, and generates an executable file. If there are errors, the compiler displays error messages indicating the problems that need to be fixed.
  2. Output: If the compilation is successful, the compiler generates an executable file with the same name as the source code file but with the .exe extension. For example, if your source code file is Program.cs, the generated executable file will be Program.exe.

The resulting .exe file can be executed by running it from the command line or by double-clicking it in a file explorer. It will run the compiled C# program, executing the instructions and producing the desired output.


Create new Text document and copy and paste the following source code save it as NewProg.cs .

Full Source C#
using System; class NewProg { static void Main(string[] args) { Console.WriteLine("My First Program"); Console.ReadKey(); } }

Go to the command prompt and issue the following command for compilation.

csc NewProg.cs

When the compiler compile the program , if any error occurred in the source code , it will display in the command prompt

After the successful compilation you will get NewProg.exe file

You can execute the file in the command prompt by giving exe file name (NewProg) .


Using the csc command on the command line provides a convenient way to compile and build C# applications without relying on integrated development environments (IDEs) like Visual Studio. It allows for a more manual and flexible approach to the compilation process.