Skip to content

Global properties are not passed into builds via SolutionCreator #367

Closed

Description

@alexthornton1

When calling SolutionCreator.TryBuild and passing it an argument for globalProperties, I expected those properties to be applied to the build across all projects, not unlike the CLI command dotnet build -p:LangVersion=12.0.

However, I tried that in a test case sort of like this one. (The real test requires a lot of machinery that I can't duplicate here, unfortunately, but these are the important parts.)

    [Theory]
    [InlineData("12.0")]
    [InlineData("13.0")]
    [InlineData("latest")]
    public void CanPassGlobalProperties(string langVersion)
    {
        // This creates a SolutionCreator with a project in it, the details of which are not
        // particularly germane here.
        SolutionCreator solution = CreateTestSolution();

        solution.TryBuild(
            restore: true,
            globalProperties: new Dictionary<string, string>() { { "LangVersion", langVersion } },
            out var _, out var output);

        // When, at this point, I interrogate the BuildOutput's events to see whether LangVersion was
        // ever set to, say, 12.0, I find that it wasn't.
    }

After looking at the source code for SolutionCreator.TryBuild, it appeared that the root cause is that globalProperties is only passed into the restore operation, but not the subsequent build operation, even though the underlying call to BuildHost.TryBuild supports it. Consequently, those global properties are being ignored.

I created PR #368 that attempts to fix the problem.

Many thanks!

Activity

  1. alexthornton1 commented on Sep 27, 2026

    @alexthornton1
    Author

    Upon further investigation, it doesn't appear that this is actually an issue. I'll need to dig a little further to figure out what mechanism is causing global properties to be passed in, but the fix I've proposed does not seem to be impacting the result. The global properties are actually there either way, just not where I expected them to be. I do find them in ProjectStartedEventArgs when I look at AllEvents in the BuildOutput.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions