简体   繁体   中英

How do I compile a single source file within an MSVC project from the command line?

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 to MSBuild.exe . Usually this should be set up for you by the VS2010 bat file so the right one will end up in your PATH , but if not I found one at C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\msbuild.exe
  • project is the path to the vcxproj 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. The sln 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's vcvarsall.bat .
  • Regarding path_to_file in the SelectedFiles 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM