Visual Studio 2010,如何在多核上并行构建项目
我有一个包含 40 多个项目的大型解决方案。其中几乎一半是测试项目。 在我的项目中,我们使用代码契约、代码分析、风格分析。 我希望能够构建不依赖于我的四核 CPU 的并行项目。
如何设置 msbuild 来并行构建项目?
I have a big solution with more than 40 projects. Almost half of them are test projects.
In my project we use both Code Contracts, Code Analysis, Style Analysis.
I want to be able to build the projects that are not dependent in parallel on my quad core CPU.
How can I setup msbuild to build the projects in parallel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Visual Studio 中:工具 |选项|项目和解决方案|构建并运行。这应该默认为您的 CPU 计数。
从命令行:
msbuild /maxcpucount[:n]
(如果未指定 n,则将使用 CPU 计数)。In Visual Studio: Tools | Options | Projects and Solutions | Build and Run. This should default to your CPU count.
From the command line:
msbuild /maxcpucount[:n]
(is n is not specified, then it will use the CPU count).您可以通过以下方式并行启动
MSBuild
中的构建:将
MSBuild
任务的属性BuildInParallel
设置为true
或者使用参数
调用msbuild /maxcpucount:X
其中X
指定构建中涉及的工作进程数。该解决方案更适合您的需求。Scott Hanselman 写了一篇文章,如果你想将这个过程集成到(有点) Visual Studio 作为外部工具。
多处理器构建:
对于 C++ 项目,您可以直接在 Visual Studio 中配置 选项|项目和解决方案|构建并运行
You could launch the build in
MSBuild
in parallel by :Setting the attribute
BuildInParallel
ofMSBuild
task totrue
Or calling msbuild with the parameter
/maxcpucount:X
whereX
specifies the number of worker processes that are involved in the build. This solution better suits your need.Scott Hanselman wrote a post on that, if you want to integrate (kinda) the process into Visual studio as an external tool.
For C++ projects you could configure multiprocessor build directly in Visual Studio :
Tools | Options | Projects and Solutions | Build and Run
我知道有一个 nmake 的克隆支持 -j 开关并行编译:
http: //qt.gitorious.org/qt-labs/jom
还有一个针对 MSbuild 的 hack,只需谷歌一下即可。我还知道有一个工具支持在多台机器上构建,也许也支持在多核上构建,但我现在不记得它的名字了。
希望这有帮助。
I know that there is a clone of nmake that supports the -j switch to compile in parallel:
http://qt.gitorious.org/qt-labs/jom
and there is also a hack for MSbuild, just google it. I also know there is a tool that supports building on multiple machines and perhaps also on multiple cores, but I dont remember its name at the moment.
hope this helps.
那么您正在寻找的真正答案是将 /MP 编译器标志添加到 CXX 编译器标志中。
在 Visual Studio 下的项目属性页> C\C++ >常规多处理器编译只需键入 Yes (/MP)。现在它将在每个核心上并行构建所有 40 个项目
Then real answer you are looking for is to add the /MP compiler flag to the CXX compiler flags.
In Visual Studio Under the project property page> C\C++ >General Multi-processor compilation just type Yes (/MP). Now it will build all 40 projects in parallel on each of the cores
现在,它已内置于 Visual Studio 11 中,适用于所有语言,而不仅仅是 C++。
“Visual Studio 2010 包含一个“并行项目构建的最大数量”选项。虽然没有任何限制的迹象,但此 IDE 选项仅适用于 C++ 项目。幸运的是,此限制不再适用于 Visual Studio 11”,来自 www.visualstudiomagazine.com
This is now built in for Visual Studio 11 for all languages, not just C++.
"Visual Studio 2010 included an option for "maximum number of parallel project builds." Although there was no indication of any restriction, this IDE option only worked for C++ projects. Fortunately, this restriction no longer applies to Visual Studio 11" from www.visualstudiomagazine.com