How can I use CSC.EXE (.NET Framework Executable) to compile C# code into executables or libraries? CSC Syntax

Abdulqadir Aliyev 101 Reputation points

Note: This question has been copied over from Originally asked here:

Hello. Recently I was trying to find out how do I compile my .CS file (C# File with C# Code) into an EXE or DLL file for my program without installing any software. I asked some of my friends in case they know, they told me to use csc (.NET Framework Feature). It is located in C:\Windows\Microsoft.NET\Framework*system dotnet framework version*\csc.exe -- Visual C# Command Line Compiler. They did not provide command-line syntax, so here's why I ask this question.

I tried to run CSC.EXE from its own path in CMD, but I got nothing that useful... (I was using no arguments)

Can anyone provide the usage of csc.exe, for operations like compiling a C# file into a library or executable?

Note: There are no system instabilities or anything whatsoever. I need this information, it is related to my program.

I did actually refer to to see CSC.exe syntax, but, didn't get what I need.

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,964 questions
No comments
{count} votes

Accepted answer
  1. Jack J Jun 19,216 Reputation points Microsoft Employee

    @AbdulqadirAliyev-3681, Welcome to Microsoft Q&A, you could try the following steps to use csc.exe to convert .cs file to an exe file.

    First, please create the following .cs file in the path C:\Test\Project.

    using System;  
    public class HelloWorld {  
        public static void Main()   
            Console.WriteLine("Hello world!");  

    Second, please open your command prompt in your computer.

    Third, please use the following cmd to convert your .cs file to exe file.

    csc.exe -out:C:\Test\Project\Program.exe C:\Test\Project\Program.cs  

    Finally, you could see the output in the console window and the exe is shown in the folder.


    Hope this could help you.

    Best Regards,

1 additional answer

Sort by: Most helpful
  1. Viorel 82,661 Reputation points

    For example, create a source file (hello.cs) like this:

    using System;  
    namespace MyNamespace  
      class MyProgram  
         static void Main( string[] args )  

    Then execute this command:

    ā€ƒC:\Windows\Microsoft.NET\.....\csc.exe hello.cs

    (Specify the correct path). It will create the hello.exe file.

    No comments