While it is possible to experience its inherent advantages while working through the command line, no one can deny that typing dozens of compiler options can result in finger cramps and typos. To help mitigate both issues, the C # compiler supports the use of response files.
Note All command prompts allow you to traverse the previous command using the UP and DOWN ARROW keys.
Response files (which, by convention, *.RSP file extensions) contain all the options that you want to supply to csc.exe. After you create the file, you can specify its name as the only option for the C # compiler. For illustration purposes, the following provides a response file that will be used to generate MyCodeLibrary.dll (note that you can use the # symbol to specify a comment).
# MyCodeLibraryArgs.rsp
# These are the options used
# to compile MyCodeLibrary.dll
# Output target and name.
/t:library
/out:MyCodeLibrary.dll
# Location of C# files.
/recurse:*.cs
# Give me an XML doc.
/doc:myDoc.xml
# Give me a strong name as well.
/keyfile:C:\MyKeyPair\myKeypair.snk
Given the file, you can now specify MYCODELIBRARYARGS.RSP with the @ option:
csc @MyCodeLibraryArgs.rsp
If you prefer, you can specify multiple response files:
csc @MyCodeLibraryArgs.rsp @MoreArgs.rsp @EvenMoreArgs.rsp
Keep in mind that the response file is processed in the order in which it was encountered. Therefore, the settings in the previous file may be overridden by the settings in a later file.
Default response files and/noconfig options
Finally, keep in mind that there is a default response file-csc.rsp, which is automatically processed by csc.exe during each compilation. If you analyze the contents of the file (which is in the same folder as the csc.exe itself), you will only find a set of frequently referenced assemblies (System.Windows.Forms.dll, System.Data.dll, and so on).
In the rare occasions where you want to ban including csc.rsp, you can specify the/NOCONFIG flag:
csc /noconfig @MyCodeLibraryArgs.rsp
Note If you reference an assembly and do not actually use it, it will not be listed in the assembly manifest. Therefore, do not worry about code bloat because they do not exist at all.