build-parallelism
$
npx mdskill add microsoft/testfx/build-parallelismOptimize MSBuild builds by maximizing CPU parallelism
- Solves underutilized cores and slow multi-project solution times.
- Depends on dotnet build, /graph mode, and binlog analysis.
- Decides actions based on dependency topology and critical paths.
- Delivers recommendations for parallel workers and scheduling.
SKILL.md
.github/skills/build-parallelismView on GitHub ↗
--- name: build-parallelism description: "Guide for optimizing MSBuild build parallelism and multi-project scheduling. Only activate in MSBuild/.NET build context. USE FOR: builds not utilizing all CPU cores, speeding up multi-project solutions, evaluating graph build mode (/graph), build time not improving with -m flag, understanding project dependency topology. Note: /maxcpucount default is 1 (sequential) — always use -m for parallel builds. Covers /maxcpucount, graph build for better scheduling and isolation, BuildInParallel on MSBuild task, reducing unnecessary ProjectReferences, solution filters (.slnf) for building subsets. DO NOT USE FOR: single-project builds, incremental build issues (use incremental-build), compilation slowness within a project (use build-perf-diagnostics), non-MSBuild build systems. INVOKES: dotnet build -m, dotnet build /graph, binlog analysis." --- ## MSBuild Parallelism Model - `/maxcpucount` (or `-m`): number of worker nodes (processes) - Default: 1 node (sequential!). Always use `-m` for parallel builds - Recommended: `-m` without a number = use all logical processors - Each node builds one project at a time - Projects are scheduled based on dependency graph ## Project Dependency Graph - MSBuild builds projects in dependency order (topological sort) - Critical path: longest chain of dependent projects determines minimum build time - Bottleneck: if project A depends on B, C, D and B takes 60s while C and D take 5s, B is the bottleneck - Diagnosis: replay binlog to diagnostic log with `performancesummary` and check Project Performance Summary — shows per-project time; grep for `node.*assigned` to check scheduling - Wide graphs (many independent projects) parallelize well; deep graphs (long chains) don't ## Graph Build Mode (`/graph`) - `dotnet build /graph` or `msbuild /graph` - What it changes: MSBuild constructs the full project dependency graph BEFORE building - Benefits: better scheduling, avoids redundant evaluations, enables isolated builds - Limitations: all projects must use `<ProjectReference>` (no programmatic MSBuild task references) - When to use: large solutions with many projects, CI builds - When NOT to use: projects that dynamically discover references at build time ## Optimizing Project References - Reduce unnecessary `<ProjectReference>` — each adds to the dependency chain - Use `<ProjectReference ... SkipGetTargetFrameworkProperties="true">` to avoid extra evaluations - `<ProjectReference ... ReferenceOutputAssembly="false">` for build-order-only dependencies - Consider if a ProjectReference should be a PackageReference instead (pre-built NuGet) - Use `solution filters` (`.slnf`) to build subsets of the solution ## BuildInParallel - `<MSBuild Projects="@(ProjectsToBuild)" BuildInParallel="true" />` in custom targets - Without `BuildInParallel="true"`, MSBuild task batches projects sequentially - Ensure `/maxcpucount` > 1 for this to have effect ## Multi-threaded MSBuild Tasks - Individual tasks can run multi-threaded within a single project build - Tasks implementing `IMultiThreadableTask` can run on multiple threads - Tasks must declare thread-safety via `[MSBuildMultiThreadableTask]` ## Analyzing Parallelism with Binlog Step-by-step: 1. Replay the binlog: `dotnet msbuild build.binlog -noconlog -fl -flp:v=diag;logfile=full.log;performancesummary` 2. Check Project Performance Summary at the end of `full.log` 3. Ideal: build time should be much less than sum of project times (parallelism) 4. If build time ≈ sum of project times: too many serial dependencies, or one slow project blocking others 5. `grep 'Target Performance Summary' -A 30 full.log` → find the bottleneck targets 6. Consider splitting large projects or optimizing the critical path ## CI/CD Parallelism Tips - Use `-m` in CI (many CI runners have multiple cores) - Consider splitting solution into build stages for extreme parallelism - Use build caching (NuGet lock files, deterministic builds) to avoid rebuilding unchanged projects - `dotnet build /graph` works well with structured CI pipelines
More from microsoft/testfx
- assertion-qualityAnalyzes the variety and depth of assertions across test suites in any language. Use when the user asks to evaluate assertion quality, find shallow testing, identify assertion-free tests (no assertions or only trivial ones like Assert.IsNotNull / expect(x).toBeTruthy() / assert x is not None), flag self-referential or tautological assertions (output equals input on identity/round-trip operations), measure assertion coverage diversity, or audit whether tests verify different facets of correctness. Produces metrics and actionable recommendations. Polyglot: .NET (MSTest/xUnit/NUnit/TUnit), Python (pytest/unittest), TS/JS (Jest/Vitest/Mocha/Jasmine/node:test), Java (JUnit/TestNG), Go, Ruby (RSpec/Minitest), Rust, Swift (XCTest/Swift Testing), Kotlin (JUnit/Kotest), PowerShell (Pester), C++ (GoogleTest/Catch2/doctest). DO NOT USE FOR: writing new tests (use code-testing-agent, or writing-mstest-tests for MSTest), anti-patterns like flakiness or duplication (use test-anti-patterns), fixing assertions.
- binlog-failure-analysisAnalyze MSBuild binary logs to diagnose build failures by replaying binlogs to searchable text logs. Only activate in MSBuild/.NET build context. USE FOR: build errors that are unclear from console output, diagnosing cascading failures across multi-project builds, tracing MSBuild target execution order, investigating common errors like CS0246 (type not found), MSB4019 (imported project not found), NU1605 (package downgrade), MSB3277 (version conflicts), and ResolveProjectReferences failures. Requires an existing .binlog file. DO NOT USE FOR: generating binlogs (use binlog-generation), build performance analysis (use build-perf-diagnostics), non-MSBuild build systems. INVOKES: dotnet msbuild binlog replay, grep, cat, head, tail for log analysis.
- binlog-generationGenerate MSBuild binary logs (binlogs) for build diagnostics and analysis. Only activate in MSBuild/.NET build context. USE FOR: adding /bl:{} to any dotnet build, test, pack, publish, or restore command to capture a full build execution trace, prerequisite for binlog-failure-analysis and build-perf-diagnostics skills, enabling post-build investigation of errors or performance. Requires MSBuild 17.8+ / .NET 8 SDK+ for {} placeholder; PowerShell needs -bl:{{}}. DO NOT USE FOR: non-MSBuild build systems (npm, Maven, CMake), analyzing an existing binlog (use binlog-failure-analysis instead). INVOKES: shell commands (dotnet build /bl:{}).
- build-perf-baselineEstablish build performance baselines and apply systematic optimization techniques. Only activate in MSBuild/.NET build context. USE FOR: diagnosing slow builds, establishing before/after measurements (cold, warm, no-op scenarios), applying optimization strategies like MSBuild Server, static graph builds, artifacts output, and dependency graph trimming. Start here before diving into build-perf-diagnostics, incremental-build, or build-parallelism. DO NOT USE FOR: non-MSBuild build systems, detailed bottleneck analysis (use build-perf-diagnostics after baselining).
- build-perf-diagnosticsDiagnose MSBuild build performance bottlenecks using binary log analysis. Only activate in MSBuild/.NET build context. USE FOR: identifying why builds are slow by analyzing binlog performance summaries, detecting ResolveAssemblyReference (RAR) taking >5s, Roslyn analyzers consuming >30% of Csc time, single targets dominating >50% of build time, node utilization below 80%, excessive Copy tasks, NuGet restore running every build. Covers timeline analysis, Target/Task Performance Summary interpretation, and 7 common bottleneck categories. Use after build-perf-baseline has established measurements. DO NOT USE FOR: establishing initial baselines (use build-perf-baseline first), fixing incremental build issues (use incremental-build), parallelism tuning (use build-parallelism), non-MSBuild build systems. INVOKES: dotnet msbuild binlog replay with performancesummary, grep for analysis.
- check-bin-obj-clashDetects MSBuild projects with conflicting OutputPath or IntermediateOutputPath. Only activate in MSBuild/.NET build context. USE FOR: builds failing with 'Cannot create a file when that file already exists', 'The process cannot access the file because it is being used by another process', intermittent build failures that succeed on retry, missing outputs in multi-project builds, multi-targeting builds where project.assets.json conflicts. Diagnoses when multiple projects or TFMs write to the same bin/obj directories due to shared OutputPath, missing AppendTargetFrameworkToOutputPath, or extra global properties like PublishReadyToRun creating redundant evaluations. DO NOT USE FOR: file access errors unrelated to MSBuild (OS-level locking), single-project single-TFM builds, non-MSBuild build systems. INVOKES: dotnet msbuild binlog replay, grep for output path analysis.
- code-testing-agent>-
- code-testing-extensions>-
- coverage-analysis>
- crap-score>