How dotnet/msbuild works
Project type and purpose
• MSBuild is a standalone build engine and CLI tool (not a web or desktop app). It reads XML‐based project/solution files, constructs build graphs, schedules and executes tasks, and emits logs/telemetry.
• The README confirms it’s a modular build platform with several components: CLI (msbuild.exe), engine libraries, tasks, utilities, logging, telemetry, and extensibility (BuildCheck, SDK resolvers).
High‐level file‐structure analysis
• Top‐level “src” contains all code, subdivided into folders:
• Microsoft.Build.CommandLine (the CLI entrypoint)
• Microsoft.Build.Engine (core parsing, evaluation, graph, backend execution)
• Microsoft.Build.Framework (interfaces/contracts for tasks, loggers)
• Microsoft.Build.Tasks (built-in task implementations)
• Microsoft.Build.Utilities (helper classes for custom tasks/loggers)
• BuildCheck plugin (static analysis checks)
• Logging, TelemetryInfra subfolders under the engine and framework for logging and telemetry components
• Tasks (detailed implementations), Utilities, and other cross-cutting libraries
• The “eng” folder holds CI/build pipeline definitions but is outside the runtime architecture.
Core architectural components
a. CLI Layer
• Microsoft.Build.CommandLine (msbuild.exe)
• Parses command-line options, instantiates BuildParameters, chooses engine configuration
b. Project Model & Parser
• Construction (Build/Construction): builds in-memory DOM of XML project files
• Definition (Build/Definition): transforms that DOM into semantic objects (Project, ProjectProperty, ProjectItem)
c. Evaluator & Expander
• Build/Evaluation: evaluates conditions, expands properties/items, populates ProjectInstance
d. Graph Builder
• Build/Graph: constructs a dependency graph of targets across projects
e. Back-end Execution
• Build.BackEnd.Components:
• Request Builder (RequestBuilder): turns graph nodes into build work units
• Scheduler (Scheduler): orders work units, resolves dependencies, allocates resources
• Communications (NodeManager, NodeLauncher): orchestrates in-proc vs out-of-proc nodes
• FileAccess Manager: tracks file reads/writes for incremental builds and caching
• Caching (Components/Caching): stores intermediate results (ConfigCache, ResultsCache)
f. Task Execution Hosts
• In-proc or out-of-proc task hosts (TaskExecutionHost, MSBuildTaskHost) load and run tasks
g. Task Libraries
• Microsoft.Build.Tasks & Tasks: predefined tasks (Compile, Copy, Exec, etc.)
• Utilities: helper classes for tasks and logging
h. Logging & Telemetry
• Build.Logging (ConsoleLogger, BinaryLogger, DistributedLogger, TerminalLogger)
• TelemetryInfra: forwards data to telemetry backends
i. Extensibility & Plugins
• BuildCheck: custom static analysis checks loaded via the engine’s plug-in points
• SDK resolvers: discover .NET SDKs, NuGet packages
Relationships and data-flow
• msbuild.exe
→ parses command line
→ loads project XML via ProjectParser
→ builds DOM (Construction) and semantic model (Definition)
→ evaluates conditions and expands items (Evaluation)
→ constructs dependency graph (Graph)
→ request builder transforms graph into work units
→ scheduler dispatches work to task hosts (in-proc / out-of-proc)
→ tasks execute against file system/processes, generate events
→ logging components listen for build events → emit console output, binary logs, telemetry
→ on completion, msbuild.exe returns exit code
Architectural patterns and principles
• Layered architecture (CLI → Parsing → Evaluation → Graph → Execution → Logging)
• Plugin/extension points (TaskHost, BuildCheck, SDK Resolver)
• Event‐driven logging (publish/subscribe of build events)
• Process isolation (in-proc vs out-of-proc task execution, node orchestration)
• Caching and incremental build support
Detail
• Layers and major subcomponents (e.g., caching, communication, file access manager) without drawing every class.
• How the BuildCheck and SDK Resolver integrate into the pipeline (hook points in evaluation or execution).
• Build pipeline (CI folder under “eng”) is shown separately as it’s for development/CI, not runtime.