Building a Project from the Command Line


You can build a Visual C++ project from the command line without first exporting a makefile (MAKEFILE, or filename.mak) and using the NMAKE utility.


The basic command syntax is


msdev FileName [/MAKE "ProjectName – ConfigName | ALL"] [/REBUILD /CLEAN /NORECURSE /OUT LogFile /USEENV]


where FileName is the name of your project (.dsp) or workspace (.dsw) file.


For example, the following syntax deletes all intermediate files and then builds a project called MyProject:


msdev MyProject.dsp /MAKE "MyProject – Win32 Debug" /REBUILD


The following syntax builds a workspace that contains (at least) two projects, building the release configuration of MyProject1 and all configurations of MyProject2, and directing the build output to a file called MyWorkspace.log:


msdev MyWorkspace.dsw /MAKE "MyProject1 – Win32 Release" "MyProject2 – ALL" /OUT MyWorkspace.log


Note   Projects created in Visual C++ versions earlier than 5.0 must first be converted before you can build them from the command line. To convert a project, open it inside the development environment.


You can also build all configurations of a certain type within a single project, for example, if you have defined multiple types of Debug configurations. For more information, see "Building by Type of Configuration."


Tip   Type msdev /? /OUT FileName to pipe the command syntax to a file.


The /MAKE Option

The /REBUILD, /CLEAN and /NORECURSE options all modify the /MAKE option, and are meaningless without it. Also, unless you specify a FileName after msdev, any /MAKE options will be ignored. /MAKE requires at least one configuration.


Parameter          Description

A valid workspace or project filename. Must have an extension of .dsp or .dsw.


The project that contains the configurations you want to build. If Filename is a workspace file, ProjectName must be a part of that workspace.



Any valid project configuration, or all configurations for a particular project. To build all configurations, simply type "ALL" for the configuration value (must be uppercase). Corresponds to the choices available from the Settings For drop-down list in the Project Settings dialog box. 


Name of an optional file used to store the build output information (valid only with the /OUT option). 



Option              Operation
/MAKE "projectname1 – configuration1 | projectname1 – configuration2 | projectname2 – configuration1 | ALL"

Builds the specified configurations. The /CLEAN option modifies /MAKE so that the specified configurations are cleaned rather than built. 


Displays usage information for the msdev command.


Deletes intermediate files created during the build process for the specified configuration(s); does not build the project configuration(s). 


Cleans and builds the specified configuration(s), including all dependent projects. Takes precedence if both /CLEAN and /REBUILD are specified.


Builds the specified project configuration(s) without building any dependent projects.

/OUT logfile

Creates a log file for the build output, which includes such information as syntax errors and warnings. If you don't specify a filename, the build output information is displayed at the command prompt and is not saved to a file. 


Directs the build system to use environment variables for the current build session, rather than the directory settings specified on the Directories tab (Tools menu, Options command). The PATH, INCLUDE and LIB paths must be set correctly for the build to succeed when /USEENV is specified.

/EX MacroName

Invokes the named macro (if the associated .dsm file is not loaded, this command will fail).

Tip   Type msdev /USEENV at the command line to launch Visual C++ and use the environment variables for the duration of that IDE session.


Building by Type of Configuration

For any single project, you can build all configurations of a certain type. The build system uses limited pattern matching to recognize the name of the configuration you specify.


For example, if your project contains Debug and Release configurations for both regular and UNICODE applications, you can build both configurations for only the UNICODE application by issuing the following command:


msdev MyProject.dsp /MAKE "MyProject – UNICODE"


Or, if your project contains several types of Debug and Release configurations, you can build all of the Debug configurations:


msdev MyProject.dsp /MAKE "MyProject – DEBUG"


This pattern matching gives you even more flexibility when customizing your batch builds.





msdev MyProject.dsp /MAKE "MyProject – Release"



想对作者说点什么? 我来说一句