Skip to content

Enlighten CallTarget task for multithreaded mode #13611

@jankratochvilcz

Description

@jankratochvilcz

Enlighten CallTarget task for multithreaded mode

Parent: #11834

Context

CallTarget is listed in the migration epic (#11834) under "No Modifications Required (added attribute only)" but remains unchecked. It invokes other targets within the same project file by delegating to MSBuild.ExecuteTargets and MSBuild.CreateTargetLists.

The task has zero cwd-dependent operations:

  • No file system access of any kind
  • No Environment.CurrentDirectory, Path.GetFullPath, or environment variable usage
  • No ProcessStartInfo usage
  • All work is delegated to the MSBuild engine via BuildEngine3
  • Instance state is a single List<ITaskItem> for collecting target outputs
  • Already decorated with [RunInMTA], indicating awareness of threading concerns

This is the simplest possible migration — attribute-only with no code changes.

Approach

Apply the PR #13045 (attribute-only) pattern: add [MSBuildMultiThreadableTask] to the class declaration. No IMultiThreadableTask implementation is needed.

  1. Decorate CallTarget with [MSBuildMultiThreadableTask].
  2. No other code changes required.

ChangeWave consideration

No behavioral change. The attribute declares the task safe for multithreaded scheduling. Observable behavior is byte-identical. No ChangeWave needed.

Test coverage assessment

Existing unit tests

CallTarget is tested via integration tests that exercise target invocation, RunEachTargetSeparately, and output collection.

Gaps to fill in this PR

  • G1 — Concurrency test. Two CallTarget instances targeting different targets execute concurrently, asserting each collects correct, independent TargetOutputs. Verifies no shared mutable state interference.
  • G2 — Baseline parity. Verify all existing tests continue to pass. [Output] TargetOutputs items are identical before and after.

Acceptance criteria

  • CallTarget decorated with [MSBuildMultiThreadableTask].
  • No IMultiThreadableTask implementation (not needed).
  • All existing tests pass on net472 and net10.0.
  • [Output] TargetOutputs items have byte-identical ItemSpec and metadata.
  • Concurrency test (G1) added and passes.
  • No new compiler warnings (warnings-as-errors in official build).
  • multithreaded-task-migration SKILL sign-off checklist walked and passes.

Implementation order

  1. Apply [MSBuildMultiThreadableTask] to CallTarget.
  2. Add G1 (concurrency) test.
  3. Run Tasks.UnitTests; verify clean.
  4. Run repo build with -v quiet to ensure no new warnings.

Risks / open questions

  • CallTarget delegates to MSBuild.ExecuteTargets, which itself should be enlightened separately (tracked in Migrate Tasks in the MSbuild repo to the new Task type #11834 under "Tasks with simple transition"). The CallTarget migration is independent — it only declares that CallTarget itself has no thread-unsafe operations. The engine handles scheduling of the called targets.
  • The [RunInMTA] attribute is already present and compatible with [MSBuildMultiThreadableTask].

References

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions