Export (0) Print
Expand All

Command-Line Building 

You can invoke the C# compiler by typing the name of its executable file (csc.exe) on the command line. If you use the Visual Studio Command Prompt (available as a shortcut on the start menu under Visual Studio Tools), all the necessary environment variables are set for you. Otherwise, you might need to adjust your path in order to invoke csc.exe to be invoked from any subdirectory on your computer. If you do not use the Visual Studio Command Prompt, it is necessary to run vsvars32.bat to set the appropriate environment variables to support command line builds. For more information on vsvars32.bat, see How to: Build from the Command Line.

If you are working on a computer that only has the .NET Framework SDK, you can use the C# compiler at the command line if you use the SDK Command Prompt, which is available from the Microsoft .NET Framework SDK menu option.

To build from the development environment, see Preparing and Managing Builds.

The csc.exe executable is usually located in the Microsoft.NET\Framework\<version> folder under the system directory. Its location may vary depending on the exact configuration on any individual computer. Multiple versions of this executable will be present on the machine if more than one version of the .NET Framework is installed on the machine. For more information about such installations, see Installing Multiple Versions of the .NET Framework.

This topic covers the following:

Rules for Command-Line Syntax

Sample Command Lines

Differences Between C# Compiler and C++ Compiler Output

Rules for Command-Line Syntax

The C# compiler uses the following rules when interpreting arguments given on the operating system command line:

  • Arguments are delimited by white space, which is either a space or a tab.

  • The caret character (^) is not recognized as an escape character or delimiter. The character is handled completely by the command-line parser in the operating system before being passed to the argv array in the program.

  • A string surrounded by double quotation marks ("string") is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument.

  • A double quotation mark preceded by a backslash (\") is interpreted as a literal double quotation mark character (").

  • Backslashes are interpreted literally, unless they immediately precede a double quotation mark.

  • If an even number of backslashes is followed by a double quotation mark, one backslash is placed in the argv array for every pair of backslashes, and the double quotation mark is interpreted as a string delimiter.

  • If an odd number of backslashes is followed by a double quotation mark, one backslash is placed in the argv array for every pair of backslashes, and the double quotation mark is "escaped" by the remaining backslash, causing a literal double quotation mark (") to be placed in argv.

Sample Command Lines

  • Compiles File.cs producing File.exe:

    csc File.cs 
    
  • Compiles File.cs producing File.dll:

    csc /target:library File.cs
    
  • Compiles File.cs and creates My.exe:

    csc /out:My.exe File.cs
    
  • Compiles all of the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

    csc /define:DEBUG /optimize /out:File2.exe *.cs
    
  • Compiles all of the C# files in the current directory producing a debug version of File2.dll. No logo and no warnings are displayed:

    csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
    
  • Compiles all of the C# files in the current directory to Something.xyz (a DLL):

    csc /target:library /out:Something.xyz *.cs
    

Differences Between C# Compiler and C++ Compiler Output

There are no object (.obj) files created as a result of invoking the C# compiler; output files are created directly. As a consequence of this, the C# compiler does not need a linker.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft