issue with using MSBUILD with maxcpucount option

依然范特西╮ 提交于 2019-12-11 05:59:38

问题


I am using MsBuild on a 4 core machine. I am giving the following command line to build 4 projects belonging to a big VC++ solution ( having more than 4 projects ALL with no mutual dependencies ). I am using Visual Studio 2008.

To speed up the build time I am trying to take advantage of the maxcpucount options but it seems not working. I was expecting that each core would build each of the 4 projects I am providing at command line. Unfortunately I measured the time of building and with or without the maxcpucount option I have the same exact result.

C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe MyVCppSolution.sln 
     /t:ProjA;ProjB;ProjC;ProjD /m

Do you know what I am doing wrong here?

Is a correct way to say "builds 4 projects of MyVCppSolution.sln solution at once" or should I run manually 4 processes each building a single project of the solution up to 4?


回答1:


MSBuild can projects in parallel. Your command line call (using /t) is asking for targets to build in parallel, which isn't exactly the design. You also have to set a flag in the core .proj file for parallel

To acheive what you want (4 items in parallel using all avail cores) you need to have an "overall" proj file that invokes msbuild and has the BuildInParallel parameter set to true. Then that call, calls your other projects. The combination of /m on msbuild.exe and BuillInParallel will give you what you want.

So that would like: (If you wanted ProjA, B, C, D built in parallel)

File buildall.proj

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion=”3.5”>
     <Target Name="default">
          <MSBuild Projects="proja.proj, projb.proj, probc.proj,prod.proj" BuildInParallel="true"/>
     </Target>
</Project>

Then you'd call buildall with

msbuild.exe buildall.proj /m:4


来源:https://stackoverflow.com/questions/3660413/issue-with-using-msbuild-with-maxcpucount-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!