`_projectDirectory` is not set on `ProjectItemInstance.TaskItems` returned by the build
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
When you run a build via the API and then inspect the `ResultsByTarget`, items in `TargetResult` won't have their `_projectDirectory` set, because `TaskItemFactory` calls this constructor on `ProjectItemInstance.TaskItem`:
https://github.com/dotnet/msbuild/blob/e923c2b80f00ec373b1f35108d4aaa45b280aa8c/src/Build/Instance/ProjectItemInstance.cs#L2070-L2073
https://github.com/dotnet/msbuild/blob/e923c2b80f00ec373b1f35108d4aaa45b280aa8c/src/Build/Instance/ProjectItemInstance.cs#L798
CPS could have read the `FullPath` built-in metadata on the items, but it can't because since the `_projectDirectory` is not set on the items, it would use the current directory and produce wrong results. Instead CPS has its own logic to get the full path of items returned:
https://github.com/dotnet/project-system/blob/6dcc31fa39ad6c922bfd73af553e37e7cdfd8b80/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Handlers/AbstractEvaluationCommandLineHandler.cs#L204
Since all the existing consumers seem to be fine with the current behavior, this is a low-pri bug that needs design. It may very well be that storing the project directory on the items may increase the memory pressure, or the project directory may get lost in translation across nodes (?) or not stored in the cache (?). I decided to still log the issue because a naïve usage of the MSBuild API will result in incorrect results when getting the `FullPath` metadata value on the items.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.