24

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?

thomas nn
  • 933
  • 3
  • 13
  • 21
  • it's not clear if this question deals with compiling directly in VS2010 or with compiling via msbuild4. Your comment below on contention during logging deserves to be an answer. – GregC Jun 20 '12 at 17:04

5 Answers5

17

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).

Richard
  • 106,783
  • 21
  • 203
  • 265
  • 14
    We also found that in Visual Studio: Tools -> Options -> Projects and Solutions -> Build and Run -> . You can set both MSBuild project build output verbosity and log file verbosity: to Quiet. This will make the build process MUCH faster and the IDE responsive during build. (It seams that VS2010 locking of IDE related to output is the main factor in the slow build process) <-- MS: Please Fix!! – thomas nn May 18 '10 at 11:46
13

You could launch the build in MSBuild in parallel by :

  • Setting the attribute BuildInParallel of MSBuild task to true

    <Target Name="RunInParallel">
      <MSBuild BuildInParallel="true"
               Projects="@(Projects)"
               Targets="RunCodeAnalysis">
      </MSBuild>
    </Target>
    
  • Or calling msbuild with the parameter /maxcpucount:X where X specifies the number of worker processes that are involved in the build. This solution better suits your need.

    msbuild [YourSolutionFile.sln] /maxcpucount:4 /p:Platform=AnyCpu;Configuration=Debug;
    

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

Julien Hoarau
  • 48,964
  • 20
  • 128
  • 117
  • Thanks, We are not into C++, but if other readers are then you should take a look at this tool: http://www.xoreax.com/visual_studio.htm – thomas nn May 18 '10 at 11:41
4

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.

kashif
  • 41
  • 1
3

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

octi
  • 1,470
  • 1
  • 17
  • 28
2

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

AlignedDev
  • 8,102
  • 9
  • 56
  • 91