specifyseveralbuildoptionsonthecommandline

Cancel
Save
Edit

Specify Several Build Options on the Command Line

When you build a large project, it is often necessary to control the nature of the build as well as provide machine-specific details. For example, you might need to specify the location of the build inputs and outputs, whether to create a Debug build or a Release build, and the platforms to build for. To accomplish this, you can specify several build options on the command line. Instead of repeatedly typing all the options on the command line, you can save them in a response file and then specify only the name of that file on the command line.

In this example, a response file Switches.rsp is used to specify /property and /target options for a project.

Response Files

A response file for MSBuild is a text file that contains one or more command-line options. Unlike a command line, a response file allows multiple lines of options and file names to be specified. Response files can be specified on the command line using the @ switch, for example:
msbuild @switches.rsp
The response file Switches.rsp contains:

# This is a response file for MSBuild
/property:Sources=C:\MyApp\sources
/property:Outputs=C:\MyApp\binaries
/property:Flavor=DEBUG
/property:Platform=x86
C:\MyApp\MyApp.proj
/target:Build;RunTests /target:SendMail
@C:\MyApp\additionalswitches.rsp

The property value that is specified in the response file takes precedence over any value that is set for the same property in the project file.

Comments in Response Files

Response files can contain comments. Comment lines begin with the # symbol:

# This is a response file for MSBuild

Comment lines and blank lines are ignored by MSBuild.

Specifying Options in Response Files


Options in response files can be specified either on a single line or on multiple lines. In Switches.rsp, the two /target options are on the same line:
/target:Build;RunTests /target:SendMail

However, each /property option is on a separate line.

Referring to Other Response Files


Response files can refer to other response files to provide other sets of options. For example, Switches.rsp references the response file

Additionalswitches.rsp:

@C:\MyApp\additionalswitches.rsp

A response file can be specified only once for each build so a response file cannot contain a reference to itself or to another response file that includes a reference to the original response file. In this example, neither Switches.rsp nor Additionalswitches.rsp can contain a reference to Switches.rsp.