Export (0) Print
Expand All
17 out of 33 rated this helpful - Rate this topic

Building from the Command Line

The C# compiler can be invoked at the command line by typing the name of its executable file (csc.exe) on the command line. You may need to adjust your path if you want csc.exe to be invoked from any subdirectory on your computer.

This topic provides details on the following:

Running VCVARS32.BAT

vcvars32.bat sets the appropriate environment variables to enable command line builds.

To run VCVARS32.BAT

  1. At the command prompt, change to the \bin subdirectory of your installation.
  2. Run VCVARS32.bat by typing VCVARS32.
    Caution   VCVARS32.bat can vary from machine to machine. Do not replace a missing or damaged VCVARS32.bat file with a VCVARS32.bat from another machine. Rerun setup to replace the missing file.

For more information about vcvars32.bat, see the following Knowledge Base article:

  • Q248802 : Vcvars32.bat Generates Out of Environment Message

If the current version of Visual Studio is installed on a computer that also has a previous version of Visual Studio, you should not run vcvars32.bat from different versions in the same command window.

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.

Rules for Command-Line Syntax

The C# compiler code 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
    

See Also

C# Compiler Options | C# Compiler Options Listed Alphabetically | C# Compiler Options Listed by Category

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.