diff --git a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs index 2a9cc0e26b0..ced6a14c4a7 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs @@ -215,21 +215,28 @@ private void ExecuteAdd(ProjectItemGroupTaskItemInstance child, ItemBucket bucke FileSystems.Default, LoggingContext); + Action> logFunction = null; + if (LogTaskInputs && !LoggingContext.LoggingService.OnlyLogCriticalEvents && itemsToAdd?.Count > 0) { - ItemGroupLoggingHelper.LogTaskParameter( - LoggingContext, - TaskParameterMessageKind.AddItem, - parameterName: null, - propertyName: null, - child.ItemType, - itemsToAdd, - logItemMetadata: true, - child.Location); + logFunction = (itemList) => + { + ItemGroupLoggingHelper.LogTaskParameter( + LoggingContext, + TaskParameterMessageKind.AddItem, + parameterName: null, + propertyName: null, + child.ItemType, + itemList, + logItemMetadata: true, + child.Location); + }; } + - // Now add the items we created to the lookup. - bucket.Lookup.AddNewItemsOfItemType(child.ItemType, itemsToAdd, !keepDuplicates); // Add in one operation for potential copy-on-write + // Now add the items we created to the lookup. + bucket.Lookup.AddNewItemsOfItemType(child.ItemType, itemsToAdd, !keepDuplicates, logFunction); + // Add in one operation for potential copy-on-write } /// diff --git a/src/Build/BackEnd/Components/RequestBuilder/Lookup.cs b/src/Build/BackEnd/Components/RequestBuilder/Lookup.cs index e0bcc5eff38..55320f37c6b 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/Lookup.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/Lookup.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Threading; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; @@ -636,7 +637,7 @@ internal void SetProperty(ProjectPropertyInstance property) /// /// Implements a true add, an item that has been created in a batch. /// - internal void AddNewItemsOfItemType(string itemType, ICollection group, bool doNotAddDuplicates = false) + internal void AddNewItemsOfItemType(string itemType, ICollection group, bool doNotAddDuplicates = false, Action> logFunction = null) { // Adding to outer scope could be easily implemented, but our code does not do it at present MustNotBeOuterScope(); @@ -663,12 +664,32 @@ internal void AddNewItemsOfItemType(string itemType, ICollection 0) { - itemsToAdd = itemsToAdd.Where(item => !existingItems.Contains(item, ProjectItemInstance.EqualityComparer)); + + var deduplicatedItemsToAdd = new List(); + foreach (var item in itemsToAdd) { + if (!existingItemsHashSet.Contains(item)) { + deduplicatedItemsToAdd.Add(item); + } + } + itemsToAdd = deduplicatedItemsToAdd; } } + if (doNotAddDuplicates) + { + logFunction?.Invoke(itemsToAdd.ToList()); + } + else { + var groupAsList = group as List; + logFunction?.Invoke(groupAsList ?? group.ToList()); + } + + PrimaryAddTable.ImportItemsOfType(itemType, itemsToAdd); }