Add the merge logic to BuildResult for handling RequestedProjectState, BuildFlags and ProjectInstance reliably #11765
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.
Fixes #11701
Context
The commit addresses an issue where Visual Studio hangs during build operations, due to inconsistent project state merging after build operations. The root cause appears to be how
BuildResult
instances handle merging of project state when multiple build operations are combined (per the sameConfigurationId
).Why These Changes Were Made
The core issue appears to be inconsistent handling of project state during build operations, particularly when:
Multiple build operations need to be merged
Different build operations request different subsets of project state
The merge operation doesn't preserve all necessary metadata, properties, or flags
Prior to this change, when build results were merged using the MergeResults method, the logic didn't properly handle the merging of project state after build.
The new implementation explicitly merges:
The project properties
The project items and their metadata
The requested state filters
The build flags
Changes Made
MergeProjectStateAfterBuildInstances
: This method properly merges project instances, including their properties, items, and requested state filters. It handles cases where instances might be null, or when one instance has a full project state versus a partial state.MergeBuildFlags
: This method provides explicit control over how build flags are merged, with special handling for theProvideProjectStateAfterBuild
andProvideSubsetOfStateAfterBuild
flags.RequestedProjectState
with Merge CapabilityAdded a new
Merge()
method toRequestedProjectState
that properly combines property filters and item filters from two different instances.Implemented sophisticated merging logic for item filters that preserves metadata from both sources.
ProjectInstance
Enhanced the FilteredCopy constructor to handle null collections gracefully.
Updated code to use modern C# collection initializers and null-safe operations.
Made the handling of various dictionaries (properties, items, etc.) more robust against null values.
ResultsCache.AreBuildResultFlagsCompatible
If a subset of data is requested, we don't need to rely on the cache flag, but check if the available subset of the data can satisfy the request.
Testing
Added UTs to cover new Merge Logic
Notes