Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,17 @@ public void UpdateShouldImportMetadataFromReferencedItem()
ObjectModelHelpers.AssertItemHasMetadata(expectedMetadataC, items[4]);
}

[Fact]
public void OptimizedRemoveOperationRespectsCondition()
{
string content = @"<TheItem Include=""InitialValue"" />
<TheItem Remove=""@(TheItem)"" Condition=""false"" />
<TheItem Include=""ReplacedValue"" Condition=""false"" /> ";
IList<ProjectItem> items = ObjectModelHelpers.GetItemsFromFragment(content, true);

items[0].EvaluatedInclude.ShouldBe("InitialValue");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void ApplyImpl(ImmutableList<ItemData>.Builder listBuilder, I
new BuildEventFileInfo(string.Empty),
"OM_MatchOnMetadataIsRestrictedToOnlyOneReferencedItem");

if (_matchOnMetadata.IsEmpty && ItemspecContainsASingleBareItemReference(_itemSpec, _itemElement.ItemType))
if (_matchOnMetadata.IsEmpty && ItemspecContainsASingleBareItemReference(_itemSpec, _itemElement.ItemType) && _conditionResult)
{
// Perf optimization: If the Remove operation references itself (e.g. <I Remove="@(I)"/>)
// then all items are removed and matching is not necessary
Expand Down