Thursday, October 7, 2010

makefile in .NET

makefile is an interesting concept in UNIX world to read its instructions from text files. In current VS enviornment, developers jst click play button in IDE. No idea beyond that. But, VS has this makefile concept via 'Response File' with extension rsp.

A response file is a text file that contains a set of compiler command line switches. When you execute CSC.exe, the compiler opens response files and uses 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 an @ sign. As an example, 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 because you don’t have to manually express the desired command-line arguments each time you want to compile your project. C# compiler supports multiple response files.

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 should 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 in %SystemRoot% folder \Microsoft.NET\Framework\vX.X.X directory (where X.X.X is version of installed .NET Framework). Settings in the local file override the global file.

When you use the /reference compiler switch to reference an assembly, you can specify a complete path to a particular file. However, if you do not specify a path, the compiler will search for the file in the following places (in the order listed):
  1. Working directory.
  2. Global file.
  3. Any directories specified using the /lib compiler switch.
  4. Any directories specified using the LIB environment variable

Itz possible for the compiler to ignore both local and global CSC.rsp files by specifying the /noconfig command-line switch


  1. Does the global csc.rsp file take effect when the project is compiled from Visual Studio? If all the projects that are part of a solution needs to have specific swithches where should the rsp file be placed and how should the project properties be configured to use those switches while compiling it from within the IDE?

  2. yes srini, global is the default. If u go to the selected project settings in VS, reference compiler switch is under Build section.