The Command-Line Compiler in C#

This chapter describes the command-line switches that you can pass to the compiler. Options that can be abbreviated are shown with the abbreviated portion in brackets ([]).

You can use the /out and /target options more than once in a single compilation, and they apply only to those source files that follow the option.

1. Simple Usage

In simple usage, you might use the following command:

csc test.cs

This compiles the file test .cs and produces a console assembly (test .exe) that can then be executed. You can specify multiple files on the same line, along with wildcards.

2. Response Files

The C# compiler supports a response file that contains command-line options. This is especially useful if you have lots of files to compile or complex options.

You specify a response file merely by listing it on the command line:

csc @<responsefile>

You can use multiple response files on a single command line, or you can mix them with options on the command line.

3. Default Response File

To avoid having to specify lots of assemblies, the compiler looks for a csc.rsp file, unless it’s specifically told not to do so. If it finds one in the current directory, it will use that file as if it had been specified with the at (@) sign syntax. If the file doesn’t exist in the current directory, it will next look in the directory where csc.exe lives.

4. Command-Line Options

The following tables summarize the command-line options for the C# compiler. Specifically, Table 41-1 specifies the error-reporting options, Table 41-2 describes the input options, Table 41-3 lists the output options, Table 41-4 specifies the processing options, and Table 41-5 shows miscellaneous options. You can also set most of these from within the Visual Studio IDE.

Source: Gunnerson Eric, Wienholt Nick (2005), A Programmer’s Introduction to C# 2.0, Apress; 3rd edition.

Leave a Reply

Your email address will not be published. Required fields are marked *