|
1 | 1 | ---
|
2 |
| -title: Using Multiple Processors to Build Projects |
3 |
| -description: Explore how MSBuild takes advantage of systems that have multiple processors or cores by creating a separate build process for each available processor. |
4 |
| -ms.date: 11/04/2016 |
5 |
| -ms.topic: how-to |
| 2 | +title: MSBuild Exploits Multiple Processors for Builds |
| 3 | +description: Explore how MSBuild can exploit systems that have multiple processors or cores by creating a separate build process for each available processor. |
| 4 | +ms.date: 06/25/2025 |
| 5 | +ms.topic: concept-article |
6 | 6 | helpviewer_keywords:
|
7 | 7 | - multiple processors
|
8 | 8 | - MSBuild, multiple processor systems
|
9 | 9 | author: ghogen
|
10 | 10 | ms.author: ghogen
|
11 | 11 | manager: mijacobs
|
12 | 12 | ms.subservice: msbuild
|
| 13 | +#customer intent: As a developer, I want to learn how MSBuild exploits systems with multiple processors or cores, so I can create separate build processes for each of my processors. |
13 | 14 | ---
|
14 |
| -# Use multiple processors to build projects |
15 | 15 |
|
16 |
| -MSBuild can take advantage of systems that have multiple processors, or multiple-core processors. A separate build process is created for each available processor. For example, if the system has four processors, then four build processes are created. MSBuild can process these builds simultaneously, and therefore overall build time is reduced. However, parallel building introduces some changes in how build processes occur. This topic discusses those changes. |
| 16 | +# MSBuild exploits multiple processors to build projects |
| 17 | + |
| 18 | +MSBuild can take full advantage of systems that have multiple processors or multiple-core processors by creating a separate build process for each processor. For example, if a system has four processors, MSBuild creates four build processes. |
| 19 | + |
| 20 | +MSBuild can process the multiple builds simultaneously, which reduces the overall build time. However, parallel builds can introduce changes in how the build processes occur. |
| 21 | + |
| 22 | +This article describes process changes that can occur when multiple builds run simultaneously. |
17 | 23 |
|
18 | 24 | ## Project-to-project references
|
19 | 25 |
|
20 |
| - When the Microsoft Build Engine encounters a project-to-project (P2P) reference while it is using parallel builds to build a project, it builds the reference only one time. If two projects have the same P2P reference, the reference is not rebuilt for each project. Instead, the build engine returns the same P2P reference to both projects that depend on it. Future requests in the session for the same target are provided the same P2P reference. |
| 26 | +When the Microsoft Build Engine encounters a project-to-project (P2P) reference during parallel builds for a project, it builds the reference one time only. If two projects have the same P2P reference, the reference isn't rebuilt for each project. Instead, the build engine returns the same P2P reference to both projects that have the dependency. MSBuild also supplies the same P2P reference to future requests in the session for the same target. |
21 | 27 |
|
22 | 28 | ## Cycle detection
|
23 | 29 |
|
24 |
| - Cycle detection functions the same as it did in MSBuild 2.0, except that now MSBuild can report the detection of the cycle at a different time or in the build. |
| 30 | +Cycle detection during parallel builds is the same behavior as for MSBuild 2.0. The one difference is that the newer version of MSBuild can report the detection of the cycle at a different time or in the build. |
25 | 31 |
|
26 | 32 | ## Errors and exceptions during parallel builds
|
27 | 33 |
|
28 |
| - In parallel builds, errors and exceptions can occur at different times than they do in a non-parallel build, and when one project does not build, the other project builds continue. MSBuild will not stop any project build that is building in parallel with the one that failed. Other projects continue to build until they either succeed or fail. However, if <xref:Microsoft.Build.Framework.IBuildEngine.ContinueOnError%2A> has been enabled, then no builds will stop even if an error occurs. |
| 34 | +During parallel builds, errors and exceptions can occur at different times than they do during a non-parallel build. Also, if one project doesn't build, the other project builds continue. |
| 35 | + |
| 36 | +MSBuild doesn't stop any project building in parallel with a failed build. Other projects continue to build until they either succeed or fail. When the <xref:Microsoft.Build.Framework.IBuildEngine.ContinueOnError%2A> setting is enabled, no builds stop, even if an error occurs. |
29 | 37 |
|
30 | 38 | ## C++ project (.vcxproj) and solution (.sln) files
|
31 | 39 |
|
32 |
| - Both C++ projects (*.vcxproj*) and solution (*.sln*) files can be passed to the [MSBuild task](../msbuild/msbuild-task.md). For C++ projects, VCWrapperProject is called, and then the internal MSBuild project is created. For C++ solutions, a SolutionWrapperProject is created, and then the internal MSBuild project is created. In both cases, the resulting project is treated the same as any other MSBuild project. |
| 40 | +Both C++ project (*.vcxproj*) and solution (*.sln*) files can be passed to the [MSBuild task](msbuild-task.md). |
| 41 | + |
| 42 | +- **C++ projects**: The VCWrapperProject API is called and then the internal MSBuild project is created. |
| 43 | +- **C++ solutions**: A SolutionWrapperProject instance is created and then the internal MSBuild project is created. |
| 44 | + |
| 45 | +In both cases, the resulting project is handled like any other MSBuild project. |
33 | 46 |
|
34 | 47 | ## Multi-process execution
|
35 | 48 |
|
36 |
| - Almost all build-related activities require the current directory to remain constant throughout the build process to prevent path-related errors. Therefore, projects cannot run on different threads in MSBuild because they would cause multiple directories to be created. |
| 49 | +Almost all build-related activities require the current directory to remain constant throughout the build process to prevent path-related errors. Projects can't run on different threads in MSBuild because they can cause the creation of multiple directories. |
37 | 50 |
|
38 |
| - To avoid this problem but still enable multi-processor builds, MSBuild uses "process isolation." By using process isolation, MSBuild can create a maximum of `n` processes, where `n` equals the number of processors available on the system. For example, if MSBuild builds a solution on a system that has two processors, then only two build processes are created. These processes are re-used to build all the projects in the solution. |
| 51 | +To avoid this problem but still enable multi-processor builds, MSBuild uses _process isolation_. This process enabled MSBuild to create a maximum of `n` processes, where `n` equals the number of processors available on the system. For example, if MSBuild builds a solution on a system with two processors, only two build processes are created. These processes are reused to build all the projects in the solution. |
39 | 52 |
|
40 | 53 | ## Related content
|
41 | 54 |
|
42 |
| -- [Build multiple projects in parallel](../msbuild/building-multiple-projects-in-parallel-with-msbuild.md) |
43 |
| -- [Tasks](../msbuild/msbuild-tasks.md) |
| 55 | +- [Build multiple projects in parallel](building-multiple-projects-in-parallel-with-msbuild.md) |
| 56 | +- [MSBuild tasks](./msbuild-tasks.md) |
0 commit comments