dotnet / dotnet/msbuild

TaskAnalyzer: report MT diagnostics as suggestions for non-MT tasks

Closed
#14,991 2 comments 1 reaction 2 assignees Claimed by @VolPlita View on GitHub
Area: Analyzer
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Problem

MT-related TaskAnalyzer diagnostics can also provide useful migration guidance for non-MT tasks. However, reporting them as warnings or errors for those tasks can disrupt builds that are not adopting multithreaded task execution.

Non-MT tasks should still receive the selected diagnostics, but only as suggestions or informational messages. MT-scoped tasks need stronger enforcement because unsafe behavior can affect other tasks running in the shared process.

### Proposed behavior

For selected MT-related diagnostics:

- Report them as Suggestion/Info for non-MT tasks, so migration guidance remains visible in the IDE without normally affecting command-line builds.
- Report the same diagnostic IDs at their intended Warning or Error severity for MT-scoped tasks.
- Always let an explicit `dotnet_diagnostic..severity` setting in `.editorconfig` or `.globalconfig` override the analyzer's contextual default.

This should apply only to diagnostics that the team wants to enforce strongly for MT tasks. Disabled and advisory rules must retain their intended defaults.

### Scope and implementation

This issue covers two parts of the same change:

1. **Behavior:** report selected MT-related diagnostics as Suggestion/Info for non-MT tasks while retaining Warning/Error enforcement for MT-scoped tasks.
2. **Implementation:** add contextual severity to TaskAnalyzer so it can select the appropriate default severity from the task context while preserving the same diagnostic ID and standard analyzer configuration.

Contextual severity is the mechanism required to implement the behavior, not a separate independent feature. The implementation must verify that an explicit `dotnet_diagnostic..severity` setting overrides the contextual default for both MT and non-MT tasks.

### Design questions

- Which diagnostic IDs should use contextual severity?
- How should this behavior interact with `msbuild_task_analyzer.run_mt_analyzers_on_all_tasks` from #14775?

Related: #14775, #14990

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.