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!
When calling
SolutionCreator.TryBuildand passing it an argument forglobalProperties, I expected those properties to be applied to the build across all projects, not unlike the CLI commanddotnet 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.)
After looking at the source code for
SolutionCreator.TryBuild, it appeared that the root cause is thatglobalPropertiesis only passed into the restore operation, but not the subsequent build operation, even though the underlying call toBuildHost.TryBuildsupports it. Consequently, those global properties are being ignored.I created PR #368 that attempts to fix the problem.
Many thanks!