I'm about to start doing some benchmarking/testing of our builds, and I'd like to drive the whole thing from a command line. I am aware of DevEnv
but am not convinced it can do what I want.
If I could have a single file built within a single project, I'd be happy.
Can this be done?
The magical incantation is as follows. Note that this has only been tested with VS 2010 - I have heard this is the first version of Visual Studio with this capability:
The Incantation
<msbuild> <project> <settings> <file>
Where
msbuild
is a path toMSBuild.exe
. Usually this should be set up for you by the VS2010bat
file so the right one will end up in yourPATH
, but if not I found one atC:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe
project
is the path to thevcxproj
file within which your source file resides.settings
include the following:/p:Configuration="Debug"
// or whatever your Configuration is/p:Platform=x64
// or x86/t:ClCompile
// to specify specifically you're looking to compile the file
file
is actually another setting:/p:SelectedFiles="path_to_file"
Notes
- For
<project>
I had to specify a project (vcxproj
) file instead of a solution (sln
) file. Thesln
I would have used has multiple projects within it, so there would have been extra work to go that route anyhow (if it can even be done). - For the
/p:Platform=x64
setting, there are several environment variables that pivot on what platform you are targeting (x64 v. x86) so make sure you set those up properly via Visual Studio'svcvarsall.bat
. - Regarding
path_to_file
in theSelectedFiles
parameter, this path must be the path as specified in the project file. If the path does not match the path used in the project file to reference the source, it doesn't seem to work.
来源:https://stackoverflow.com/questions/9285756/how-do-i-compile-a-single-source-file-within-an-msvc-project-from-the-command-li