问题
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?
回答1:
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
msbuildis a path toMSBuild.exe. Usually this should be set up for you by the VS2010batfile so the right one will end up in yourPATH, but if not I found one atC:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exeprojectis the path to thevcxprojfile within which your source file resides.settingsinclude 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
fileis 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. TheslnI 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=x64setting, 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_filein theSelectedFilesparameter, 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