Response files in C# compilation

By Jatin Prajapati

The FAQ explains about the Response files in C# compilation of code.

A response file is a text file that contains a set of compiler command-line switches. When you execute CSC.exe, the compiler opens resonse files and use any switches that are specified in them as though the switches were passed to CSC.exe on the command line. You instruct the compiler to use a response file by specifying its name on the command line prepended by a @ sign. For example, you could have a response file called MyProject.rsp that contains the following text:



To execute CSC.exe to use these settings, you would invoke it as follows:

csc.exe @MyProject.rsp CodeFile1.cs CodeFile2.cs

This tells the C# compiler what to name the output file and what kind of target to create. As you can see, response files are very convenient becuase you don't have to manually express the desired command-line arguments each time you want to compile your project.

The C# compiler supports multle response files. In addition to the files you explicitly specify on the command line, the compiler automatically looks for files called CSC.rsp. When you run CSC.exe, it looks in the current directory for a local CSC.rsp file - you sould place any project-specific settings in this file. The compiler also looks in the directory containing the CSC.exe file for a global CSC.rsp file. Settings that you want applied to all of you projects should go in this file.

When you install the .NET Framework, it installs a default global CSC.rsp file in the %SystemRoot%\Microsoft.NET\Framework\vX.X.Xdirectory (where X.X.X is the version of the .NET Framework you have installed). The 4.0 version of the file contains the following switches:

# This file contains command-line options that the C#
# command line compiler (CSC) will process as part
# of every compilation, unless the "/noconfig" option
# is specified.
# Reference the common Framework libraries

Becuase the global CSC.rsp file references all of the assemblies listed, you do not need to explicitly reference these assemblies by using the C# compiler's /reference switch.

Response files in C# compilation  (1617 Views)