dotnet / dotnet/msbuild

[Bug]: all references to metadata(in an Item element inside a Target) always refer to the value prior to evaluating the Item element

Open
#10,721 5 comments 0 reactions 0 assignees View on GitHub
Area: Documentation Priority:2 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

When using item metadata within an Item element contained inside a Target, the value of the metadata always evaluates to its value immediately before entering the Item element. That is, any updates to metadata inside an Item element are not reflected in later references to that metadata inside the same Item element

### Steps to Reproduce

A minimal sample project is available at https://github.com/Arthri/msbuild_demo_batching

1. Include some items into a group
2. Create a target which operates over the items and changes some metadata
3. In the same Item element, update metadata conditionally using the metadata that was changed

Miminal sample
```xml



default data
new default


```

### Expected Behavior

The condition should've used the new value of the metadata, and outputted four warnings containing "new default"

### Actual Behavior

The condition used the old value of the metadata: the metadata before entering the Item element in the ItemGroup, and outputted four warnings containing "default data"

### Analysis

I believe that MSBuild is replacing the metadata before entering the Item element, and when the condition runs, it never sees the updated metadata values.

Assuming the aforementioned is true, it can be concluded that spreading the metadata updates over several Item elements should work. And from my testing, I've observed that this is a working solution
```xml


default data


new default

```

### Versions & Configurations

.NET SDK version `8.0.400`
MSBuild version `17.11.3.35201` / `17.11.3+0c8610977`
Microsoft Visual Studio version `17.11.3`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.