title: MSBuild - How to build multiple files AND projects in parallel
body: <p>I have a large Visual Studio 2010 solution file (<code>.sln</code>) that contains a large number of projects (<code>~50</code>). Each project consists of roughly <code>20</code> <code>.cpp</code> and <code>.h</code> files. Building the entire project takes roughly 2 hours on a fast Intel i7 machine with all the dependencies cached locally on a fast SSD.</p>
  
  <p>I am attempting to <a href="https://randomascii.wordpress.com/2014/03/22/make-vc-compiles-fast-through-parallel-compilation/" rel="noreferrer">replicate an existing experiment I found on this topic</a>, and need some clarification on how to:</p>
  
  <ol>
  <li>Get the parallelization I'm seeking to work in Visual Studio (with the GUI/IDE).</li>
  <li>Get these changes also working with automated command-line builds via <code>MSBuild.exe</code>.</li>
  </ol>
  
  <p>First, are the <code>/m</code> and <code>/maxcpucount</code> options the same? I've <a href="http://www.hanselman.com/blog/FasterBuildsWithMSBuildUsingParallelBuildsAndMulticoreCPUs.aspx" rel="noreferrer">read an article on the <code>/m</code> option,</a> which seems to build more <strong>projects</strong> in parallel. This appears to be the same option I set via the following actions in the GUI:</p>
  
  <ul>
  <li><kbd>Tools</kbd>
  
  <ul>
  <li><kbd>Options</kbd></li>
  <li><kbd>Projects and Solutions</kbd></li>
  <li><kbd>Build and Run</kbd>
  
  <ul>
  <li><code>Maximum number of parallel project builds</code></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>There is another option, <code>/MP</code>, which I can reach in the GUI via:</p>
  
  <ul>
  <li><kbd>Projects</kbd>
  
  <ul>
  <li><kbd>Properties</kbd></li>
  <li><kbd>Configuration Properties</kbd></li>
  <li><kbd>C/C++</kbd>
  
  <ul>
  <li><kbd>General</kbd></li>
  <li><code>Multi-processor Compilation</code></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Please correct me if I'm wrong on this, but this seems to suggest that the project will build multiple <code>.cpp</code> files in parallel, but there's no option to specify how many, unless I have to manually set it in the text box (ie: <code>/MP 4</code> or <code>/MP4</code>. </p>
  
  <p>It also seems that in order for <code>/MP</code> to work, I need to disable minimal rebuild (ie: <code>Enabled Minimal Rebuild: No (/GM-)</code>), and it also doesn't work with pre-compiled headers. I've worked around the pre-compiled headers issue by making the precompiled headers be a dedicated project that the solution builds first, before all other projects.</p>
  
  <p>To the question: How can I implement these options for parallel project builds within the solution, and parallel file (<code>.cpp</code>) builds within the projects, using MSBuild via the command-line, and confirm that they are working as expected? Are my assumptions above also correct? <strong>My end goal is to test building the project with up to the total number of cores being uses, or possibly even overloading it if my build process is I/O bound rather than CPU bound.</strong> I can do this easily enough in Linux via:</p>
  
  <pre><code>NUMCPUS=`grep -c '^processor' /proc/cpuinfo`
  NUMJOBS="$(echo "$NUMCPUS*1.5" | bc)"
  NUMJOBS="$(printf '%.0f' $NUMJOBS)"
  alias pmake='time nice make -j$NUMJOBS'
  </code></pre>
  
  <p>This allows me to, on my 8-core PC, queue up 12 build tasks at once, and <code>make</code> automatically builds up to 12 <code>.cpp</code> files in parallel, handling implicit build rules/dependencies, etc. I'm trying to achieve the same thing in Visual Studio Professional and MSBuild. When my builds are I/O bound, this approach has been the best at keeping all cores at <code>~100%</code> usage.</p>
  
  <p>Thank you.</p>