Skip to content

Automatic MSBuild Registration via Module Initializer #371

@YuliiaKovalova

Description

@YuliiaKovalova

Summary

Add a zero-configuration option for MSBuildLocator that automatically registers a default MSBuild instance without requiring an explicit call to MSBuildLocator.RegisterDefaults().

Motivation

Currently, every consumer of MSBuildLocator must explicitly call MSBuildLocator.RegisterDefaults() (or one of the other Register* methods) before using any MSBuild APIs. For users who don't need to customize which MSBuild instance is used, this is unnecessary ceremony.
A common question from new users: "Why do I need to call RegisterDefaults() if I never customize the MSBuild location?"
For the majority use case where the default behavior is acceptable, requiring explicit initialization adds friction without providing value.
Proposed Solution
Use a module initializer to automatically register a default MSBuild instance when the assembly loads.

Opt-out mechanism

Introduce an MSBuild property to control this behavior:
<MSBuildLocatorGenerateDefaultInitialization>false</MSBuildLocatorGenerateDefaultInitialization>
When set to false, the automatic initialization file would not be generated, allowing users to retain full control over registration timing and configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions