You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #14315 adds support for injecting TaskEnvironment into task constructors, so tasks can compute environment-dependent property defaults during construction (something the property-set path cannot do, because property initializers run before the engine assigns the TaskEnvironment property).
During review, @jankratochvilcz suggested discouraging the older property-set pattern in favor of the new constructor-injection path. Marking IMultiThreadableTask.TaskEnvironment[Obsolete]/[Deprecated] outright is not viable — it is still the primary supported API, and many 1P and 3P builds compile with /warnAsError, so the resulting warnings would be a hard build break for every task that sets it (ToolTask and all built-in tasks). An analyzer is a better, opt-in fit and was deliberately kept out of #14315 to avoid inflating its scope.
Proposal
Add a Roslyn analyzer that nudges task authors toward constructor-based TaskEnvironment injection:
Surface an informational/warning diagnostic (green squiggle) when a task consumes TaskEnvironment only via the post-construction property-set path where constructor injection would be preferable.
Ensure it does not fire on existing built-in tasks in a way that breaks /warnAsError builds (ship as an opt-in/info-severity diagnostic, or scope it appropriately).
Include analyzer unit tests and documentation for the recommended pattern.
Activity
Add analyzer for TaskEnvironment constructor injection (dotnet#14401)