Skip to content

Scope MT-specific TaskAnalyzer diagnostics to MT tasks by default - #14775

Open
VolPlita wants to merge 6 commits into
dotnet:mainfrom
VolPlita:vplita-mt-only-default
Open

Scope MT-specific TaskAnalyzer diagnostics to MT tasks by default#14775
VolPlita wants to merge 6 commits into
dotnet:mainfrom
VolPlita:vplita-mt-only-default

Conversation

@VolPlita

@VolPlita VolPlita commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Part of #14078

Context

This is a narrow, incremental scope change for MT-specific migration diagnostics. It does not define TaskAnalyzer's complete shipping policy.

MSBuildTask0002, MSBuildTask0003, and related MSBuildTask0005 findings describe MT migration work. Reporting them on every regular task by default can add warnings when customers only update the analyzer package. Always-applicable MSBuildTask0001 and MSBuildTask0004 findings remain active for regular tasks, including through MSBuildTask0005 call chains.

Changes Made

  • Uses multithreadable_only as the default scope for MSBuildTask0002, MSBuildTask0003, and their transitive MSBuildTask0005 findings.
  • Keeps direct and transitive MSBuildTask0001/MSBuildTask0004 findings active for regular tasks.
  • Keeps all as an explicit migration mode.
  • Recognizes IMultiThreadableTask, [MSBuildMultiThreadableTask], and [MSBuildMultiThreadableTaskAnalyzed] as MT opt-ins.
  • Reads the supported bare msbuild_task_analyzer.scope global option and removes the unreachable dotted build_property lookup.
  • Adds real .globalconfig tests for direct and transitive analysis. A section-based .editorconfig intentionally does not set this compilation-wide option.
  • Verifies all three MT opt-ins for direct and transitive analysis: IMultiThreadableTask, [MSBuildMultiThreadableTask], and [MSBuildMultiThreadableTaskAnalyzed].
  • Configures Microsoft.Build.Tasks with scope = all only when BuildAnalyzer=true, preserving repository migration coverage.
  • Updates the scope and severity documentation.

Testing

  • TaskAnalyzer.Tests: 282 passed, 0 failed, 0 skipped.
  • Standard repository build: 0 warnings, 0 errors.
  • Analyzer-enabled repository build: 161 expected TaskAnalyzer warnings, 0 errors.
  • Confirmed TaskAnalyzer.globalconfig is included only when BuildAnalyzer=true.

Scope Relative to Follow-up PRs

The direct migration configuration supported by this PR is:

is_global = true
msbuild_task_analyzer.scope = all

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts TaskAnalyzer’s default analysis behavior so multi-threading (MT) diagnostics don’t introduce new warnings for “regular” tasks when the analyzer ships broadly (e.g., with Microsoft.Build.Framework), while still allowing an explicit migration mode to analyze all tasks.

Changes:

  • Changed the default scope behavior to analyze MT-specific rules only for MT-opted-in tasks, with scope=all enabling migration-mode analysis for all tasks.
  • Applied scope gating to MSBuildTask0002/MSBuildTask0003 and to task-root selection for MSBuildTask0005, with new/updated tests covering default/all/invalid values.
  • Updated analyzer documentation/comments to reflect the new default behavior (with a remaining config-mechanism doc mismatch noted in PR comments).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/TaskAnalyzer/SharedAnalyzerHelpers.cs Changes scope option parsing to default to MT-only and only enable all-tasks when explicitly set to all.
src/TaskAnalyzer/MultiThreadableTaskAnalyzer.cs Updates scope documentation/comments to match new default behavior.
src/TaskAnalyzer/README.md Updates public documentation for new default scope and migration-mode behavior.
src/TaskAnalyzer.Tests/TestHelpers.cs Refactors helpers to make “all” explicit and adds helpers for default-scope runs.
src/TaskAnalyzer.Tests/MultiThreadableTaskAnalyzerTests.cs Adds tests validating default vs all scope behavior and invalid values.
src/TaskAnalyzer.Tests/TransitiveCallChainAnalyzerTests.cs Adds tests validating MSBuildTask0005 behavior under default vs all scope.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@@ -17,8 +17,8 @@ namespace Microsoft.Build.TaskAuthoring.Analyzer
/// Roslyn analyzer that detects unsafe API usage in MSBuild task implementations.
///
/// Scope (controlled by .editorconfig option "msbuild_task_analyzer.scope"):
@@ -18,25 +18,25 @@ internal static class SharedAnalyzerHelpers
{
/// <summary>
/// The .editorconfig key controlling analysis scope.
Comment thread src/TaskAnalyzer/README.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@VolPlita
VolPlita marked this pull request as ready for review August 24, 2026 12:13
@JanProvaznik

Copy link
Copy Markdown
Member

@VolPlita please resolve the conflict and give this PR a more meaningful title

@AR-May

AR-May commented Aug 24, 2026

Copy link
Copy Markdown
Member

expert review AI report:
Review complete. Verdict: 🔴 Request changes — direction is right, but the change doesn't achieve its stated goal.

Blocking

  1. Goal not met: only 0002/0003/0005 are gated. MSBuildTask0001 (Error), 0004, 0009 (Warning), 0010 (Error) still fire on every regular  ITask  — a customer updating  Microsoft.Build.Framework  gets build-breaking errors with no opt-out.  UnsupportedTaskItemTypeAnalyzer  never even reads the scope option. Either gate everything on MT opt-in, or narrow the PR's claim explicitly.
  2. The opt-in is unreachable:  build_property.msbuild_task_analyzer.scope  requires an MSBuild property named with a dot — impossible — and no  CompilerVisibleProperty / build/*.props  is packed. All  scope=all  tests seed exactly that dead key; the bare-key  .globalconfig  path the README documents has zero coverage.

Major

• Config path (your question #2): ship    +  build/*.props . Avoid per-tree  .editorconfig  — MSBuildTask0005 filters at  CompilationEnd  and has no syntax tree, so scopes would disagree.
•  TestHelpers  now routes the whole legacy ~250-test suite through  ScopeAll , so the new shipping default is the least-tested config.
• Five XML comments still say  .editorconfig , contradicting the README's  .globalconfig .

Moderate

• Transitive analyzer builds the full compilation call graph, then discards it at  CompilationEnd  under the new default — pure cost for the common case.
• Your question #1: MSBuildTask0005 shouldn't be blanket-suppressed for regular roots — filter by violation category, so transitive 0001/0004 still report. But if you take the "gate everything" route in B1, the current root filter becomes correct and this dissolves. Answer B1 first.

Nits: title typo ("nt" → "mt"), missing newline at EOF,  ImplementsInterface  helper open-coded.

@VolPlita VolPlita changed the title default nt only Default TaskAnalyzer scope to multithreadable tasks only Aug 25, 2026
@VolPlita VolPlita changed the title Default TaskAnalyzer scope to multithreadable tasks only Limit MSBuildTask0002, 0003, and 0005 to MT tasks by default Aug 25, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@VolPlita VolPlita changed the title Limit MSBuildTask0002, 0003, and 0005 to MT tasks by default Scope MT-specific TaskAnalyzer diagnostics to MT tasks by default Aug 25, 2026
VolPlita and others added 2 commits August 26, 2026 01:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
VolPlita added a commit that referenced this pull request Aug 26, 2026
…askItem<T> (#14811)

Part of #14078.

### Summary

Aligns TaskAnalyzer descriptor severities with the documented intent and
prevents an unsupported-type false positive when a task uses an open
generic `ITaskItem<T>` property.

This PR intentionally does **not** change `msbuild_task_analyzer.scope`.
The scope-policy implementation and tests belong to #14775 and are
excluded from this PR.

### Changes

- Changes MSBuildTask0006, MSBuildTask0007, and MSBuildTask0008 from
**Warning** to **Info**. These rules provide modernization suggestions
with code fixes; they do not report invalid task definitions.
- Changes MSBuildTask0010 from **Error** to **Warning**.
`Convert.ChangeType` binding succeeds, but its invariant-culture
behavior may not match the task's intended parsing semantics.
- Keeps MSBuildTask0009 as **Warning**, avoiding a new unconditional
build break for existing analyzer consumers.
- Skips MSBuildTask0009 for open generic `ITaskItem<T>` properties
because an unresolved type parameter does not provide enough information
to determine whether the closed task parameter will be supported.
- Updates `DiagnosticDescriptors.cs`, `AnalyzerReleases.Unshipped.md`,
the README, and analyzer tests so all severity declarations agree.
- Adds coverage showing typed task-item diagnostics apply to regular
tasks independently of MT opt-in and that open generic task-item
properties do not produce a diagnostic.

### Compatibility

The severity changes only reduce diagnostics from Warning/Error to
Info/Warning. No new warning or error is introduced, and analyzer scope
behavior is unchanged.

### Testing

- `.dotnet\dotnet.exe test
src\TaskAnalyzer.Tests\TaskAnalyzer.Tests.csproj -c Release`: 250
passed, 0 failed, 0 skipped.
- `.\build.cmd -v quiet`: succeeded with 0 warnings and 0 errors.

### Related

- #14775 owns the analyzer scope-policy change and is not reimplemented
here.
- MSBuildTask0005 redesign remains follow-up work in #14777.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@VolPlita
VolPlita enabled auto-merge (squash) August 26, 2026 11:29
@AR-May
AR-May disabled auto-merge August 26, 2026 11:44
@AR-May

AR-May commented Aug 27, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@AR-May

AR-May commented Aug 27, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants