Skip to content

Design a clean way to work with AbsolutePath and ITaskItem #13820

Open

Description

@AR-May

The multithreaded-task migration introduces AbsolutePath and TaskEnvironment.GetAbsolutePath(string) as the safe way to resolve paths inside tasks. In practice, the vast majority of path-typed task inputs arrive as ITaskItem rather than string, so the current migration pattern is:

 AbsolutePath p = TaskEnvironment.GetAbsolutePath(item.ItemSpec);

This has two problems:

  1. Ergonomics. Every task migration repeats the conversion to AbsolutePath. Path-typed outputs going back into ITaskItem are also awkward.
  2. Cross-project correctness. When an item with a relative ItemSpec flows from project A to project B, GetAbsolutePath(item.ItemSpec) re-anchors it to B's directory. The engine-stamped FullPath metadata (anchored to A) might be what the task actually means. See discussion in Migration of GenerateBindingRedirects #13771 (comment).

Goal:
Design a first-class, ergonomic way for tasks to move between ITaskItem and AbsolutePath that is correct in cross-project scenarios, plays well with the analyzer/codefix, and reads naturally at the call site.

Activity

  1. added
    Area: TasksIssues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll.
    on May 20, 2026
  2. rainersigwald commented on May 20, 2026

    @rainersigwald
    Member

    Yes, as you correctly pointed out in that comment, Path.GetFullPath(itemFromAnotherProject.ItemSpec) and itemFromAnotherProject.GetProperty("FullPath") can differ--but I think the latter is what folks usually want so I'd like the new API to guide people to something like that. @AlesProkop correctly captured the behavior of the task, but I thought it was a bug at first . . .

  3. baronfel commented on May 20, 2026

    @baronfel
    Member

    When we implement this we should add an analyzer rule to detect use of ItemSpec (at least detecting when itemspec is used in TaskEnvironment.GetAbsolutePath`) and guide users to using other fields, because we think ItemSpec is almost always not what users should use.

    field meaning recommended use suggested alternative API
    ItemSpec raw user/msbuild logic input only logging/serialization .GetMetadata("FullPath")
    .GetMetadata("FullPath") absolute path to the Item all file I/O TaskEnvironment.GetAbsolutePath(item)
  4. jankratochvilcz commented on Jun 2, 2026

    @jankratochvilcz
    Contributor

    this will also require some investigation.

  5. jankratochvilcz commented on Jun 16, 2026

    @jankratochvilcz
    Contributor

    Grooming Discussion (June 2, 2026)

    Key points from the grooming session:

    • FullPath metadata investigation needed — the FullPath metadata is not populated correctly in all cases. The team needs someone to investigate where in the code the incorrect behavior originates (beyond the behavioral observation already documented).
    • Design options requested — before the design discussion, the team wants documented alternatives for how tasks should work with ITaskItem that may contain relative paths.
    • Interaction with MT analyzer — this design decision should ideally land before the MT task analyzer is publicly promoted, since the analyzer's guidance on ITaskItem handling depends on the chosen approach. However, it doesn't need to block the initial analyzer publication.
    • Current workaround — both MSBuild and SDK tasks are currently working around the issue by casting ItemSpec to absolute path on the fly, which is functional but not a clean long-term pattern.
  6. baronfel commented on Jun 16, 2026

    @baronfel
    Member

    One of the clean ways to interact with this may be to leverage the type-binding in my PRs to remove the need for Task authors to ever consider this question in the first place.

  7. removed their assignment
    on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: MultithreadedArea: TasksIssues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions