Skip to content

Global properties are not passed into builds via SolutionCreator #367

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

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