Track exact source locations on evaluated items - #14731
Open
AlesProkop wants to merge 3 commits into
Open
Conversation
Capture the source line and column when items are created and preserve them through cloning and node serialization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5a5ff63d-77fe-442e-892d-53ae50064596
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 076fff95-d760-471e-8afc-423a9701f8a5
Contributor
There was a problem hiding this comment.
Pull request overview
Adds end-to-end propagation of precise MSBuild item source locations (file/line/column) from evaluation through task execution, enabling downstream tooling (for example NuGet) to report diagnostics that can navigate back to the originating <Item ... /> XML element.
Changes:
- Introduces
ITaskItem3.Locationplus a new immutableTaskItemLocationvalue type to expose item-origin locations to tasks and consumers. - Stores and preserves source line/column on
ProjectItemInstancetask items across cloning, snapshots, task outputs, and node serialization. - Updates key item-production paths (evaluation, intrinsic item transforms, task output inference) and adds focused unit tests validating location retention and serialization.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Utilities/TaskItem.cs | Implements ITaskItem3 and copies/publishes source location when wrapping/copying items for tasks. |
| src/Framework/TaskItemLocation.cs | Adds new public TaskItemLocation struct implementing IMSBuildElementLocation. |
| src/Framework/TaskItem_T.cs | Extends TaskItem<T> to implement ITaskItem3 and forward Location from backing items. |
| src/Framework/ITaskItem3.cs | Adds new ITaskItem3 interface exposing TaskItemLocation? Location. |
| src/Build/Instance/ProjectItemInstance.cs | Stores line/column on the backing task item, exposes Location, and serializes the new fields across nodes. |
| src/Build/Instance/ProjectInstance.cs | Captures XML element line/column at evaluation time when instantiating ProjectItemInstance. |
| src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs | Propagates task parameter XML location onto task-emitted output items. |
| src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs | Preserves source location when inferring task outputs via ProjectItemInstanceFactory. |
| src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs | Preserves source location when expanding/translating items in intrinsic ItemGroup handling. |
| src/Build.UnitTests/InstanceFromRemote/FakeProjectItemElementLink.cs | Implements a non-throwing Location for the fake link used by remote-instance tests. |
| src/Build.UnitTests/Instance/TaskItem_Tests.cs | Extends serialization test to assert location survives translation. |
| src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs | Adds test asserting evaluated items (and copied utility items) retain originating XML location. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2905535
Context
Tasks currently receive evaluated items without the exact source XML location, preventing diagnostics such as NU1510 from navigating to the declaring
PackageReference. Reconstructing the location later from the item type and evaluated include is ambiguous, so this records the location when the item is created.Changes Made
ITaskItem3.Locationand the immutableTaskItemLocationvalue type.ProjectItemInstance.TaskItem, reusing the existing defining-project path for the file.Microsoft.Build.Utilities.TaskItemandTaskItem<T>.Testing
ProjectItemInstance_Tests.LocationTracksOriginatingItemElement— verifies evaluated items and copied utility items retain the originating XML element location.TaskItem_Tests.Serialization— verifies line and column survive node serialization.net11.0andnet472.ProjectInstancecreation with 1,000, 10,000, and 100,000 items:e872f0f0c8e977a927f883d662d9768c86f050c3:Notes
Locationidentifies the immediate XML element that produced the item; it is not a full provenance chain.