msbuild: No error for Item update in target
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
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 5
- Comments: 22 (18 by maintainers)
Commits related to this issue
- Remove redundant Update attribute (#4144) Inside a target, Update on items is ignored (microsoft/msbuild#2835). This is harmless in this case because the update was intended to apply to all items... — committed to dotnet/sdk by rainersigwald 7 years ago
- Remove PackageReference Update via Target - MSBuild ignores it :disappointed: https://github.com/dotnet/msbuild/issues/2835 — committed to augustoproiete-sandbox/cake-extensions by augustoproiete 6 years ago
I don’t know what we need to do about this bug, but we need to do something.
Indeed it is painful! That’s why we’re investing a lot right now on a path forward which we’re calling analyzers and tracking with https://github.com/dotnet/msbuild/issues?q=is%3Aissue+is%3Aopen+label%3A"Feature%3A+Warning+Waves"+.
If you do support an opt-in behavior change, also support an opt-in warning (maybe a common msbuild errors analyzer, since we’ve found a number of ways in msbuild to shoot yourself in the foot) so all instances can be identified and validated for the opt-in behavior change.
@rainersigwald, sounds like even nowarn options are insufficient to consider automatic new warnings a non-breaking change… leaves me curious and sounds like a painful development impediment.
or make it work properly after users opt in
Instead of going the roundabout way, why not make the
Updateattribute work? At this point, it would be better than adding a warning when people expect it to work!@clairernovotny the nature of the breaking change makes that not seem like a great idea to me. We’ve found instances of this in basically all .NET repos as well as user projects. It’s not clear to me that the benefit is worth the change, since it could be a subtle silent behavior change to presumably-working targets (after the authors worked around the bad behavior somehow to get it to meet their needs).
Maybe we should consider making it actually work as one expects rather than erroring in Dev16? The examples shown above so far would not break. I am nervous as always about breaking changes, so we should search for more data on whether there are cases of an update on anything but the entire set, that are actually depending on their bug.
yep the old syntax works perfectly, I assumed that since there was no
Updatemetadata added it actually tried to update (which is exactly what’s discussed on the linked issue).Looks like a duplicate of https://github.com/Microsoft/msbuild/issues/1618, but that should have been fixed long ago (by throwing an error on the not-actually-supported
Update-inside-a-target syntax).If you change your target to use syntax like https://github.com/Microsoft/msbuild/issues/1618#issuecomment-275691043, it should work.
I repro the problem with 15.1.548.43366, so it looks like the error never worked 😦