如何从命令行编译MSVC项目中的单个源文件? [英] How do I compile a single source file within an MSVC project from the command line?

查看:236
本文介绍了如何从命令行编译MSVC项目中的单个源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将开始对我们的构建进行一些基准测试/测试,我想从命令行来驱动整个过程.我知道DevEnv,但不确信它可以满足我的要求.

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.

可以做到吗?

推荐答案

神奇的咒语如下.请注意,此功能仅在VS 2010中经过测试-我听说这是具有此功能的Visual Studio的第一个版本:

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:

<msbuild> <project> <settings> <file>

哪里

  • msbuildMSBuild.exe的路径.通常,应该通过VS2010 bat文件为您设置此文件,这样正确的文件就会出现在您的PATH文件中,但是如果没有,我会在C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe
  • 文件中找到一个文件
  • project是源文件所在的vcxproj文件的路径.
  • settings包括以下内容:
    • /p:Configuration="Debug"//或任何您的配置
    • /p:Platform=x64//或x86
    • /t:ClCompile//具体指定您要编译的文件
    • 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
          • /p:SelectedFiles="path_to_file"
          • 对于<project>,我必须指定一个项目(vcxproj)文件而不是解决方案(sln)文件.我本来会使用的sln中包含多个项目,所以无论如何(如果可以完成的话)都需要进行额外的工作.
          • 对于/p:Platform=x64设置,有几个环境变量会根据您要定位的平台(x64 v.x86)而变化,因此请确保通过Visual Studio的vcvarsall.bat正确设置了这些环境变量.
          • 关于SelectedFiles参数中的path_to_file,此路径必须是项目文件中指定的路径 .如果该路径与项目文件中用于引用源的路径不匹配,则该路径似乎无效.
          • 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.

          这篇关于如何从命令行编译MSVC项目中的单个源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆