-
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
31 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
af1e727
Merge branch 'main' into main
jimpark 1970dd1
Update MicrosoftBuildVersion to 18.7.0
invalid-email-address 055366e
Merge pull request #1 from jimpark/main-update-msbuild-version-for-an…
jimpark 6c5d5b7
Merge branch 'dotnet:main' into main
jimpark 7accd44
Merge branch 'dotnet:main' into main
jimpark 3d5b40e
Merge branch 'dotnet:main' into main
jimpark 23ef479
Fix build errors by removing unused Xunit.Abstractions reference
338af44
Merge branch 'main' into main
jimpark 0983f2b
Merge branch 'main' into main
jimpark e696e0d
Merge branch 'dotnet:main' into main
jimpark 14bf2b0
Merge branch 'dotnet:main' into main
jimpark e940634
Merge branch 'dotnet:main' into main
jimpark 676f2dd
Merge branch 'dotnet:main' into main
jimpark 5276142
Update MicrosoftBuildVersion to 18.8.0
invalid-email-address a8ba934
Merge pull request #2 from jimpark/main-update-msbuild-version-for-an…
jimpark 29a04c7
Merge branch 'dotnet:main' into main
jimpark 730ce3b
Merge branch 'dotnet:main' into main
jimpark dd3e56a
Merge branch 'dotnet:main' into main
jimpark 2fba265
Merge branch 'dotnet:main' into main
jimpark 5bb788e
Merge branch 'dotnet:main' into main
jimpark 8758c78
Update MicrosoftBuildVersion to 18.9.0
invalid-email-address c0a1517
Merge branch 'dotnet:main' into main
jimpark e4f4449
Merge pull request #3 from jimpark/main-update-msbuild-version-for-an…
jimpark 2a494a7
Merge branch 'dotnet:main' into main
jimpark 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.