Skip to content

No error for Item update in target #2835

Open
@dasMulli

Description

@dasMulli

Ran into this while creating a workaround to patch an existing target (https://github.com/dotnet/cli/issues/6397#issuecomment-347989664) and naively using the item update syntax inside a target to update the link metadata of an item.
However, using the update syntax inside a target seems to update the metadata of all items, which is unexpected.

Steps to reproduce

Project file

<Project DefaultTargets="PrintResults">
  <ItemGroup>
    <SomeStaticItem Include="Item1" SomeMeta="MetaVal1" />
    <SomeStaticItem Include="Item2" SomeMeta="MetaVal2" />
    <SomeStaticItem Include="Item3" SomeMeta="MetaVal3" />

    <SomeStaticItem Update="Item2" SomeMeta="ChangedMetaVal2" />
  </ItemGroup>

  <Target Name="CreateRuntimeUpdatedItems">
    <ItemGroup>
      <SomeRuntimeItem Include="@(SomeStaticItem)" />
      <SomeRuntimeItem Update="Item2" SomeMeta="ChangedMetaVal2" />
    </ItemGroup>
  </Target>

  <Target Name="PrintResults" DependsOnTargets="CreateRuntimeUpdatedItems">
    <Message Importance="high" Text="static item: %(SomeStaticItem.Identity): SomeMeta=%(SomeStaticItem.SomeMeta)" />
    <Message Importance="high" Text="runtiime item:%(SomeRuntimeItem.Identity): SomeMeta=%(SomeRuntimeItem.SomeMeta)" />
  </Target>
</Project>

Command line

dotnet msbuild

Expected behavior

Error for Update syntax not being allowed inside targets

or

  static item: Item1: SomeMeta=MetaVal1
  static item: Item2: SomeMeta=ChangedMetaVal2
  static item: Item3: SomeMeta=MetaVal3
  runtiime item:Item1: SomeMeta=MetaVal1
  runtiime item:Item2: SomeMeta=ChangedMetaVal2
  runtiime item:Item3: SomeMeta=MetaVal3

Actual behavior

  static item: Item1: SomeMeta=MetaVal1
  static item: Item2: SomeMeta=ChangedMetaVal2
  static item: Item3: SomeMeta=MetaVal3
  runtiime item:Item1: SomeMeta=ChangedMetaVal2
  runtiime item:Item2: SomeMeta=ChangedMetaVal2
  runtiime item:Item3: SomeMeta=ChangedMetaVal2

Environment data

dotnet msbuild /version output: tested on 15.5.179.9764 and 15.6.12.27473 .

OS info:

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc): macOS 10.13.2, dotnet cli

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: EngineIssues impacting the core execution of targets and tasks.Breaking ChangeFeature: Warning WavesWarnings to enable in opt-in waves. Formerly "strict mode".

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions