Microsoft.Build (MSBuild)

repository·main·Indexed 26 days ago

https://github.com/dotnet/msbuild

A versatile build engine that uses XML-based project files to orchestrate software builds across Windows, Linux, and macOS. This documentation covers building MSBuild from source, programmatic access via namespaces like Microsoft.Build.Framework, and advanced technical topics including Native AOT and trimming support, binary log debugging, and the mt-migration GitHub Copilot plugin for multithreaded task migration.

Tokens
110.2K
Snippets
153
Records
578
Agent score
88%

What's inside MSBuild

  1. Overview of the MSBuild Build Coordinator

    main

    The MSBuild Build Coordinator is a resource management system that orchestrates and enforces fair-share allocation of build nodes across multiple simultaneous MSBuild processes. It runs as a separate process (MSBuild.Coordinator) and uses named pipes for Inter-Process Communication (IPC).

    Its primary functions include:

    • Enforcing a global node budget: Defaults to the processor count to prevent system resource exhaustion.
    • Fair-share allocation: Distributes available nodes among competing builds.
    • Build health monitoring: Uses periodic heartbeats to track active builds.
    • Nested grant support: Allows child processes to share a parent's node grant to prevent deadlocks.
    • Auto-shutdown: The coordinator shuts down after a period of inactivity.
  2. Overview of Microsoft.Build API namespaces

    main

    The Microsoft.Build.dll package provides the core APIs for interacting with MSBuild. The functionality is divided into three primary namespaces:

    • Microsoft.Build.Evaluation: Used for evaluating MSBuild projects (e.g., resolving properties and items).
    • Microsoft.Build.Construction: Used for creating and editing the structure of MSBuild projects (the XML representation).
    • Microsoft.Build.Execution: Used for the actual execution and building of MSBuild projects.
  3. Overview of PerfStar performance tracking

    main
    PerfStar is a performance tracking and investigation tool designed specifically for MSBuild. It captures performance measurements of the main MSBuild branch on a scheduled basis. Developers can use PerfStar to request experimental runs and collect performance data for proposed changes, allowing for the measurement of in-development features and the impact of performance improvement tasks with concrete numbers and minimal external interference.
  4. Overview of Microsoft.Build (MSBuild)

    main
    Microsoft.Build (MSBuild) is a platform for building applications. It uses an XML schema for project files to control how the build platform processes and builds software. While Visual Studio uses MSBuild, the engine can run independently by invoking msbuild.exe on project or solution files, allowing for build orchestration in environments without Visual Studio installed.
  5. Overview of Microsoft.NET.StringTools

    main

    The Microsoft.NET.StringTools package provides the Microsoft.NET.StringTools assembly, which implements common string-related functionality, specifically including features like weak interning.

    Note: This package is currently intended primarily as an internal implementation detail for MSBuild and Visual Studio. If you intend to use this package for external projects, the maintainers request that you start a discussion at https://github.com/dotnet/msbuild/discussions to communicate your use cases.

  6. Overview of BuildCheck feature

    main

    BuildCheck is a feature introduced in .NET 9.0 designed to allow the MSBuild team to evangelize build best practices and provide customers with tools to formalize and distribute their own build standards. It enables the notification of problems related to build performance and security through specialized 'Checks'.

    For detailed technical specifications, refer to the BuildCheck Spec.

  7. Understand MSBuild AOT and Trimming Annotation Strategies

    main

    This documentation outlines how MSBuild manages compatibility with Native AOT and Trimming through specific annotations. It details the relationship between [RequiresUnreferencedCode] (RUC) and [DynamicallyAccessedMembers] (DAM) to ensure that reflective code paths are correctly identified and guarded.

    Key concepts include:

    • RUC ([RequiresUnreferencedCode]): Used to mark code that relies on reflection and may fail if the target type is trimmed.
    • DAM ([DynamicallyAccessedMembers]): Used to specify which members of a type must be preserved by the trimmer.
    • Feature Switches: Used to gate reflective subsystems (like plugin loading or logger initialization) so they can be disabled in AOT/Trimmed environments, allowing the trimmer to safely remove those code paths.
  8. Access MSBuild brand assets

    main
    The branding/ directory contains various MSBuild logo and icon assets for use in applications, documentation, or NuGet packages. Available formats include SVG for scalable vector graphics and PNG for rasterized icons of specific dimensions.
  9. Understand MSBuild Trim/AOT suppression status

    main

    The MSBuild repository maintains a backlog of warnings related to Native AOT and Trimming compatibility (specifically RequiresUnreferencedCode annotations). These warnings are not false positives; they indicate paths that reach subsystems not yet ready for trim/AOT environments.

    When these paths are encountered in a trimmed/AOT MSBuild environment, the system is designed to fail observably rather than silently. You may encounter the following build errors:

    • MSB4283: ReflectiveTaskExecutionNotSupported (via InvalidProjectFileException)
    • TaskLoadFailure
    • TaskInstantiationFailureError
    • InvalidProjectFileException
  10. Understand BuildCheck Execution Modes

    main

    BuildCheck operates in two primary modes:

    • Live Mode: Integrates directly into the build execution (similar to compilation checks). This is the default for users opting-in to real-time checking.
    • Replay Mode: Performs checks post-build by analyzing a binary log. This prevents performance impact on the actual build process and supports analyzing builds from .NET 9.0 / VS 17.12 or newer.
  11. Understand MSBuild Trim and Native AOT suppression status

    main

    The MSBuild repository maintains a tracker for IL (Intermediate Language) warnings related to Trimming and Native AOT compatibility. These warnings (e.g., IL2026, IL2080, IL3050) indicate code that uses reflection or dynamic features that might be removed during trimming or fail under Native AOT.

    Status categories for these suppressions include:

    • Vetted: The warning is a provable false positive. The code is either unreachable via property functions or uses bounded allowlists (e.g., AvailableStaticMethods) that ensure required members are preserved via [DynamicDependency].
    • Backlog: The code currently requires additional feature work to be trim/AOT-ready. These are not silent failures; they are expected to fail with observable errors if triggered.

    If you encounter build errors related to reflective task execution, it may be due to the EnableReflectiveTaskExecution feature gate being disabled under trim settings.