dotnet / dotnet/msbuild

Well-known item metadata not usable in ItemDefinitionGroup

Open
#14,865 0 comments 1 reaction 2 assignees Claimed by @AR-May View on GitHub
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Issue Description

It seems that [well-known item metadata](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-well-known-item-metadata?view=visualstudio), in this example metadata like `%(Filename)` and `%(Extension)`, are not applicable to newly constructed items inside or outside targets.

The documentation for [item definitions](https://learn.microsoft.com/en-us/visualstudio/msbuild/item-definitions?view=visualstudio) says that "The values for metadata that is defined in an ItemDefinitionGroup can come from many different sources [...] **Well-known metadata on an Item from an ItemDefinitionGroup**". I would expect that metadata such as `%(Filename)` would be available, but it seems not.

### Steps to Reproduce

1. Create the below "proj.csproj" file
2. Optionally, create the files `test1.txt`, `test2.txt`, `test3.txt`, `test4.txt`. I don't believe it's necessary for MSBuild to use this metadata, but I did this to be safe
3. Run MSBuild with binlogger on this file
4. Observe that none of the created items have metadata `TargetPath="test#.txt"`

```xml



%(Filename)%(Extension)


%(BBB.Filename)%(BBB.Extension)











```

### Expected Behavior

We should create 4 items, where each has `TargetPath` metadata assigned to its filename (e.g. `test1.txt`)

### Actual Behavior

None of the items created have this metadata, and instead reuse

Image

### Analysis

_No response_

### Versions & Configurations

MSBuild version: 17.14.51+25f168cee

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.