Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions documentation/specs/multithreading/thread-safe-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ public bool Execute(...)
}
```

### Tasks That Construct Other Tasks

The engine assigns `TaskEnvironment` only to the task instances it creates itself. A task that instantiates another task directly must pass its own environment along, otherwise the inner task keeps `TaskEnvironment.Fallback` and resolves paths and environment variables against the shared process state:

```csharp
_runningExec = new Exec
{
BuildEngine = BuildEngine,
TaskEnvironment = TaskEnvironment, // required: the engine does not inject here
Command = Command,
};
```

The task-authoring analyzer reports `MSBuildTask0012` at Warning severity when a multithreadable task constructs an `ITask` without handing it a `TaskEnvironment` — through the object initializer, a constructor argument, or a later assignment on the instance — and offers a code fix that adds the initializer entry.

## Appendix: Alternatives

This appendix collects alternative approaches considered during design.
Expand Down
Loading
Loading