-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix unresolved P2P references losing Configuration in solution builds #13458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jimpark
wants to merge
7
commits into
dotnet:main
Choose a base branch
from
jimpark:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+474
−4
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02bcc36
Fix unresolved P2P references losing Configuration in solution build…
5fa4dca
Merge branch 'dotnet:main' into main
jimpark 8576ac1
Update src/Tasks/AssignProjectConfiguration.cs
jimpark ba4fdfb
Add PR requested tests
5c2f7b9
Trigger CI rerun
678fef8
Retry CI
14c5e33
Add stronger tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
src/Tasks.UnitTests/AssignProjectConfigurationChangeWave_Tests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections; | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Shared; | ||
| using Microsoft.Build.Tasks; | ||
| using Microsoft.Build.Utilities; | ||
| using Shouldly; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace Microsoft.Build.UnitTests | ||
| { | ||
| /// <summary> | ||
| /// Tests for the ChangeWave 18.6 behavior change in AssignProjectConfiguration: | ||
| /// When project references are not found in the solution configuration blob, | ||
| /// they should inherit the parent's Configuration and Platform rather than | ||
| /// having them stripped via GlobalPropertiesToRemove. | ||
| /// </summary> | ||
| public sealed class AssignProjectConfigurationChangeWave_Tests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public AssignProjectConfigurationChangeWave_Tests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that when ShouldUnsetParentConfigurationAndPlatform is true, | ||
| /// unresolved project references do NOT get GlobalPropertiesToRemove=Configuration;Platform | ||
| /// set on them. This ensures child projects inherit the parent's Configuration and Platform | ||
| /// rather than falling back to their defaults (which breaks non-standard configuration names | ||
| /// like "Debug Unicode"). | ||
| /// </summary> | ||
| [Fact] | ||
| public void UnresolvedReferencesDoNotStripConfigurationUnderChangeWave() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(_output); | ||
|
|
||
| var projectRefs = new ArrayList(); | ||
| // This reference is NOT in the solution config → will be unresolved | ||
| var unresolvedRef = ResolveNonMSBuildProjectOutput_Tests.CreateReferenceItem( | ||
| "Utility.vcxproj", | ||
| "{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}", | ||
| "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", | ||
| "Utility"); | ||
| projectRefs.Add(unresolvedRef); | ||
|
|
||
| // Solution config only contains a DIFFERENT project | ||
| var projectConfigurations = new Hashtable(); | ||
| projectConfigurations.Add("{BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB}", @"Debug Unicode|x64"); | ||
|
|
||
| string xmlString = ResolveNonMSBuildProjectOutput_Tests.CreatePregeneratedPathDoc(projectConfigurations); | ||
|
|
||
| MockEngine engine = new MockEngine(_output); | ||
| AssignProjectConfiguration task = new AssignProjectConfiguration(); | ||
| task.BuildEngine = engine; | ||
| task.SolutionConfigurationContents = xmlString; | ||
| task.ProjectReferences = (ITaskItem[])projectRefs.ToArray(typeof(ITaskItem)); | ||
| task.ShouldUnsetParentConfigurationAndPlatform = true; | ||
|
|
||
| bool result = task.Execute(); | ||
| result.ShouldBeTrue(); | ||
|
|
||
| // The reference should be unresolved (not in solution config) | ||
| task.UnassignedProjects.Length.ShouldBe(1); | ||
| task.AssignedProjects.Length.ShouldBe(0); | ||
|
|
||
| // Under ChangeWave 18.6, GlobalPropertiesToRemove should NOT include Configuration;Platform | ||
| ITaskItem unresolved = task.UnassignedProjects[0]; | ||
| string globalPropertiesToRemove = unresolved.GetMetadata("GlobalPropertiesToRemove"); | ||
| globalPropertiesToRemove.ShouldNotContain("Configuration"); | ||
| globalPropertiesToRemove.ShouldNotContain("Platform"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that when ShouldUnsetParentConfigurationAndPlatform is false, | ||
| /// unresolved references never had GlobalPropertiesToRemove set (this behavior | ||
| /// is unchanged by the ChangeWave). | ||
| /// </summary> | ||
| [Fact] | ||
| public void UnresolvedReferencesWithoutShouldUnsetDoNotStripConfiguration() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(_output); | ||
|
|
||
| var projectRefs = new ArrayList(); | ||
| var unresolvedRef = ResolveNonMSBuildProjectOutput_Tests.CreateReferenceItem( | ||
| "Utility.vcxproj", | ||
| "{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}", | ||
| "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", | ||
| "Utility"); | ||
| projectRefs.Add(unresolvedRef); | ||
|
|
||
| var projectConfigurations = new Hashtable(); | ||
| projectConfigurations.Add("{BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB}", @"Debug Unicode|x64"); | ||
|
|
||
| string xmlString = ResolveNonMSBuildProjectOutput_Tests.CreatePregeneratedPathDoc(projectConfigurations); | ||
|
|
||
| MockEngine engine = new MockEngine(_output); | ||
| AssignProjectConfiguration task = new AssignProjectConfiguration(); | ||
| task.BuildEngine = engine; | ||
| task.SolutionConfigurationContents = xmlString; | ||
| task.ProjectReferences = (ITaskItem[])projectRefs.ToArray(typeof(ITaskItem)); | ||
| task.ShouldUnsetParentConfigurationAndPlatform = false; // default for non-solution builds | ||
|
|
||
| bool result = task.Execute(); | ||
| result.ShouldBeTrue(); | ||
|
|
||
| task.UnassignedProjects.Length.ShouldBe(1); | ||
| ITaskItem unresolved = task.UnassignedProjects[0]; | ||
| string globalPropertiesToRemove = unresolved.GetMetadata("GlobalPropertiesToRemove"); | ||
| globalPropertiesToRemove.ShouldBeEmpty(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that resolved references still get correct SetConfiguration and SetPlatform | ||
| /// metadata with configurations containing spaces. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ResolvedReferencesPreserveSpacesInConfigurationName() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(_output); | ||
|
|
||
| var projectRefs = new ArrayList(); | ||
| var resolvedRef = ResolveNonMSBuildProjectOutput_Tests.CreateReferenceItem( | ||
| "Main.vcxproj", | ||
| "{CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC}", | ||
| "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", | ||
| "Main"); | ||
| projectRefs.Add(resolvedRef); | ||
|
|
||
| // Solution config contains this project with a space in config name | ||
| var projectConfigurations = new Hashtable(); | ||
| projectConfigurations.Add("{CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC}", @"Debug Unicode|x64"); | ||
|
|
||
| string xmlString = ResolveNonMSBuildProjectOutput_Tests.CreatePregeneratedPathDoc(projectConfigurations); | ||
|
|
||
| MockEngine engine = new MockEngine(_output); | ||
| AssignProjectConfiguration task = new AssignProjectConfiguration(); | ||
| task.BuildEngine = engine; | ||
| task.SolutionConfigurationContents = xmlString; | ||
| task.ProjectReferences = (ITaskItem[])projectRefs.ToArray(typeof(ITaskItem)); | ||
| task.ShouldUnsetParentConfigurationAndPlatform = true; | ||
|
|
||
| bool result = task.Execute(); | ||
| result.ShouldBeTrue(); | ||
|
|
||
| task.AssignedProjects.Length.ShouldBe(1); | ||
| task.UnassignedProjects.Length.ShouldBe(0); | ||
|
|
||
| ITaskItem resolved = task.AssignedProjects[0]; | ||
| resolved.GetMetadata("SetConfiguration").ShouldBe("Configuration=Debug Unicode"); | ||
| resolved.GetMetadata("SetPlatform").ShouldBe("Platform=x64"); | ||
| resolved.GetMetadata("Configuration").ShouldBe("Debug Unicode"); | ||
| resolved.GetMetadata("Platform").ShouldBe("x64"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that existing GlobalPropertiesToRemove metadata on an unresolved reference | ||
| /// is preserved (not appended to) under ChangeWave 18.6. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ExistingGlobalPropertiesToRemovePreservedForUnresolvedReferences() | ||
| { | ||
| using TestEnvironment env = TestEnvironment.Create(_output); | ||
|
|
||
| var projectRefs = new ArrayList(); | ||
| var unresolvedRef = ResolveNonMSBuildProjectOutput_Tests.CreateReferenceItem( | ||
| "Utility.vcxproj", | ||
| "{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}", | ||
| "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", | ||
| "Utility"); | ||
| // Set some pre-existing GlobalPropertiesToRemove | ||
| unresolvedRef.SetMetadata("GlobalPropertiesToRemove", "TargetFramework"); | ||
| projectRefs.Add(unresolvedRef); | ||
|
|
||
| var projectConfigurations = new Hashtable(); | ||
| projectConfigurations.Add("{BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB}", @"Debug|x64"); | ||
|
|
||
| string xmlString = ResolveNonMSBuildProjectOutput_Tests.CreatePregeneratedPathDoc(projectConfigurations); | ||
|
|
||
| MockEngine engine = new MockEngine(_output); | ||
| AssignProjectConfiguration task = new AssignProjectConfiguration(); | ||
| task.BuildEngine = engine; | ||
| task.SolutionConfigurationContents = xmlString; | ||
| task.ProjectReferences = (ITaskItem[])projectRefs.ToArray(typeof(ITaskItem)); | ||
| task.ShouldUnsetParentConfigurationAndPlatform = true; | ||
|
|
||
| bool result = task.Execute(); | ||
| result.ShouldBeTrue(); | ||
|
|
||
| task.UnassignedProjects.Length.ShouldBe(1); | ||
| ITaskItem unresolved = task.UnassignedProjects[0]; | ||
| string globalPropertiesToRemove = unresolved.GetMetadata("GlobalPropertiesToRemove"); | ||
|
|
||
| // The pre-existing TargetFramework should still be there | ||
| globalPropertiesToRemove.ShouldContain("TargetFramework"); | ||
| // But Configuration;Platform should NOT be appended | ||
| globalPropertiesToRemove.ShouldNotContain("Configuration"); | ||
| globalPropertiesToRemove.ShouldNotContain("Platform"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.