You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
It seems likely that some projects are relying on the current behaviour already. Are there easy ways to analyse public source code to measure how common that is?
@rainersigwald It seems like documentation concerning expansion in conditions does not mention this situation in detail: "The value of an %-expression in a target is evaluated at run-time and depends on any state changes during target execution.".
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
Miminal sample
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
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
The text was updated successfully, but these errors were encountered: