Preserve original DefiningProject* item metadata on item copy
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Steps to reproduce
Given the following project:
```xml
netstandard2.0
false
True
True
Resources.resx
ResXFileCodeGenerator
Resources.Designer.cs
```
Building the project shows the following output:
```
1>------ Build started: Project: Sample, Configuration: Debug Any CPU ------
1>Before: DefiningProjectFullPath=C:\Delete\DefiningProject\DefiningProject\Sample.csproj
1>Sample -> C:\Delete\DefiningProject\DefiningProject\bin\Debug\netstandard2.0\Sample.dll
1>After: DefiningProjectFullPath=C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
```
### Expected behavior
There should be a way to know the original defining project information throughout a build for items that are declared by the project, regardless of how they are updated or replaced by targets, at least while they are being copied from the original items. Maybe like the `OriginalItemSpec` that's used elsewhere, a new set of `OriginalDefiningProject*` metadata could be introduced on item copy, if not already present (from a previous copy, say).
### Actual behavior
The `DefiningProjectDirectory`, `DefiningProjectExtension`, `DefiningProjectFullPath` and `DefiningProjectName` are lost whenever the items are replaced with targets like
https://github.com/Microsoft/msbuild/blob/master/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L121-L125 and
https://github.com/Microsoft/msbuild/blob/master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L1241-L1244.
This makes it very hard for targets that need to know the original source of an item (i.e. to determine it belongs to a shared project) in order to act.
### Environment data
This is reproducible in all versions of MSBuild 15.
### Workaround
You can define a target that will run at the very beginning of the build and copy the original metadata to custom named metadata, which is subsequently preserved across the build:
```xml
...
%(DefiningProjectDirectory)
%(DefiningProjectExtension)
%(DefiningProjectFullPath)
%(DefiningProjectName)
```
You must do the same thing for every item type you want to preserve that metadata for.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.