visual-studio 有什么方法可以从命令行构建 Visual Studio“仅限项目”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/123632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Any way to do Visual Studio "project only" build from command line?
提问by Owen
devenv mysolution.sln /build "Release|Win32" /project myproject
When building from the command line, it seems I have the option of doing a /buildor /rebuild, but no way of saying I want to do "project only" (i.e. not build or rebuild the specified project's dependencies as well). Does anyone know of a way?
从命令行构建时,似乎我可以选择执行 a/build或/rebuild,但不能说我想做“仅项目”(即不构建或重建指定项目的依赖项)。有谁知道一种方法?
回答by Derek Slager
Depending on the structure of your build system, this may be what you're looking for:
根据您的构建系统的结构,这可能是您正在寻找的:
msbuild /p:BuildProjectReferences=false project.proj
回答by Ben Straub
Don't call devenv, use the genericized build tool instead:
不要调用devenv,而是使用泛型构建工具:
vcbuild subproject.vcproj "release|win32"
回答by Ilia K.
According to MSDN How To: Build Specific Targets in Solutions with MSBuild.exe:
根据 MSDN How To: Build Specific Targets in Solutions with MSBuild.exe:
msbuild foo.sln /t:proj1:Rebuild;folder_of_proj2\proj2:Clean
回答by cr_az
How to build a project, not an entire solution - MSDN article
如何构建一个项目,而不是一个完整的解决方案 - MSDN 文章
回答by Denkkar
The following works well for building a single C++ project in VS2010:
以下适用于在 VS2010 中构建单个 C++ 项目:
call "%VS100COMNTOOLS%"\vsvars32.bat
msbuild /detailedsummary /p:Configuration=Debug /p:Platform=x64 /t:build MY_ABSOLUTE_PATH.vcxproj
Sadly, you can't simply specify a project name and a solution file to build just that project (unless you add a special configuration to your project files perhaps).
遗憾的是,您不能简单地指定项目名称和解决方案文件来构建该项目(除非您可能向项目文件添加特殊配置)。
回答by Owen
Thanks for the answers. I see from a bit of looking into msbuildthat it can deal with a .slnfile rather than a .vcproj; can this be accomplished that way instead of having to know the location of the .vcproj?
感谢您的回答。我从一些调查中msbuild看到它可以处理.sln文件而不是.vcproj; 这可以通过这种方式完成,而不必知道 的位置.vcproj吗?
Let me take a step back. We have a big solution file and I want a script to do this:
让我退后一步。我们有一个很大的解决方案文件,我想要一个脚本来做到这一点:
- Do a
/buildon the whole solution.
(Sometimes some projects fail becausedevenvdoesn't do quite as much building as necessary for the amount of change since the last build.) - For each project that fails, do a
/rebuildon it.
/build在整个解决方案上做一个。
(有时一些项目会失败,因为devenv没有按照自上次构建以来的变化量进行必要的构建。)- 对于每个失败的项目,
/rebuild对其进行处理。
When I get to step 2 all I know is the solution filename and the names (not filenames) of the projects that failed. I could easily grep/awk/whatever the .slnfile to map from one to the other, but I'm curious if msbuildoffers a way to do it directly.
当我进入第 2 步时,我只知道解决方案文件名和失败项目的名称(不是文件名)。我可以很容易地grep//awk将.sln文件从一个映射到另一个,但我很好奇是否msbuild提供了一种直接执行此操作的方法。
(Ideally I could give msbuildthe .slnand the names of allthe projects to rebuild in a single command line, as it's a large file and takes a while to load. If that's not possible then the option of manually finding all the project filenames is probably better as loading the solution file every time would be most inefficient.)
(理想情况下,我可以给msbuild的.sln和的名字所有的项目在一个命令行来重建,因为它是一个大的文件,需要一段时间来加载。如果这是不可能的,那么手动查找所有项目文件名的选项可能是更好因为每次加载解决方案文件效率最低。)

