Skip to content

MatchOnMetadata not recognized on evaluation item removes (outside of target elements) #6985

@cdmihai

Description

@cdmihai

Steps to Reproduce

<Project>

  <ItemGroup>
    <I1 Include='a1' M1='1'/>
    
    <I2 Include='b1' M1='1'/>
    <I2 Include='b2' M1='2'/>

    <I2 Remove='@(I1)' MatchOnMetadata='M1'/>
  </ItemGroup>

  <Target Name="Build">
    <Message Text="I2: %(I2.Identity) M1=%(I2.M1)" />
  </Target>

</Project>

Build the project with msbuild foo.proj

Expected Behavior

Build works and outputs:

Microsoft (R) Build Engine version 17.0.0-preview-21515-03+d66a44095 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/22/2021 12:24:54 PM.
Project "E:\delete\play\foo.proj" on node 1 (default targets).
Build:
  I2: b2 M1=2
Done Building Project "E:\delete\play\foo.proj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Actual Behavior

Build fails with output:

Microsoft (R) Build Engine version 17.0.0-preview-21515-03+d66a44095 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/22/2021 12:27:25 PM.
Project "E:\delete\play\foo.proj" on node 1 (default targets).
MSBUILD : error : Only item types may be referenced when removing with MatchOnMetadata. [E:\delete\play\foo.proj]
Done Building Project "E:\delete\play\foo.proj" (default targets) -- FAILED.


Build FAILED.

"E:\delete\play\foo.proj" (default target) (1) ->
  MSBUILD : error : Only item types may be referenced when removing with MatchOnMetadata. [E:\delete\play\foo.proj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.08

Analysis

It works inside targets.
What's weird is that there's plenty of tests on remove with MatchOnMetadata outside of targets: https://github.com/dotnet/msbuild/blob/main/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs#L2431

Versions & Configurations

latest

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions