Skip to content

Limit TaskAnalyzer review and transitive warnings to MT-scoped tasks - #14777

Merged
AR-May merged 6 commits into
dotnet:mainfrom
VolPlita:vplita-transitive-violations
Oct 16, 2026
Merged

AR-May merged 6 commits into
dotnet:mainfrom
VolPlita:vplita-transitive-violations

Conversation

@VolPlita

@VolPlita VolPlita commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Related issue(s): #14993 (follow-up only)

Context

Regular tasks currently receive MSBuildTask0004 warnings and some MSBuildTask0005 warnings without opting into MT analysis. These warnings can fail builds that treat warnings as errors.

The previous version of this PR made MSBuildTask0005 inherit the originating rule's effective severity. This revision replaces that approach with smaller scope changes. Both rules keep their Warning defaults.

Changes Made

  • Apply MSBuildTask0004 only to MT-scoped code, using the existing scope check for MSBuildTask0002 and MSBuildTask0003.
  • Apply MSBuildTask0005 only to call chains from MT-scoped tasks. Remove the exceptions that enabled transitive MSBuildTask0001 and MSBuildTask0004 findings for regular tasks.
  • Preserve msbuild_task_analyzer.run_mt_analyzers_on_all_tasks = true. It explicitly enables these checks for regular tasks. Configuration still follows the source file containing the unsafe call.
  • Update duplicate detection so an MT task can still report an unsafe MSBuildTask0004 call inside a regular task used as a helper. Do not add a transitive report when direct analysis already reports the call.
  • Remove severity inheritance, custom reporting descriptors, custom severity tags, and manual compiler/suppression handling. Roslyn handles MSBuildTask0005 severity and suppression normally.
  • Update the rule documentation, release notes, unit regressions, and packaged-consumer checks.

MT scope still includes tasks with a directly applied MT or analyzed attribute, and tasks that directly declare IMultiThreadableTask. Direct analysis also covers explicitly analyzed helpers and contributing source base classes. Inheriting the interface alone does not opt a task into MT analysis.

Compatibility

MSBuildTask0004 and MSBuildTask0005 default to Warning. MSBuildTask0001 remains Info and still checks direct calls in regular tasks.

Regular tasks no longer receive MSBuildTask0004 or MSBuildTask0005 findings by default. Explicit migration analysis restores this coverage. Code shared with an MT-scoped task can still receive warnings as part of that task's analysis.

MSBuildTask0005 is an independent rule. It can report a Warning for a helper API covered by informational MSBuildTask0001. Changing or suppressing an originating rule does not change MSBuildTask0005. Configure or suppress MSBuildTask0005 itself. Its severity = default setting restores Warning.

Rule IDs, call-chain messages, unsafe-call locations, additional task-entry locations, and normal Roslyn suppressions remain unchanged. Task execution and runtime routing do not change. No engine ChangeWave is needed because the default change narrows analyzer warnings rather than adding warnings to existing regular tasks.

Testing

Validation used the repository SDK 11.0.100-rc.1.26420.103, with MSBUILDUSESERVER=0 and MSBUILDDISABLENODEREUSE=1.

  • dotnet test src\TaskAnalyzer.Tests\TaskAnalyzer.Tests.csproj -c Release — passed: 409 tests, 0 failed, 0 skipped. Build: 0 warnings and 0 errors.
  • .\build.cmd -v quiet — passed: 0 warnings and 0 errors.
  • After call artifacts\msbuild-build-env.bat, dotnet --version — passed: 11.0.100-rc.1.26420.103.
  • In that bootstrap environment, dotnet build src\Samples\Dependency\Dependency.csproj -v:q — passed: 0 warnings and 0 errors.
  • artifacts\bin\bootstrap\core\dotnet.exe msbuild -help — passed: locally built MSBuild 18.13.0-dev.26513.1.
  • dotnet format whitespace src\TaskAnalyzer\TaskAnalyzer.csproj --no-restore --verify-no-changes --include src\TaskAnalyzer\MultiThreadableTaskAnalyzer.cs src\TaskAnalyzer\TransitiveCallChainAnalyzer.cs — passed. The formatter emitted a workspace-load warning.
  • dotnet format whitespace src\TaskAnalyzer.Tests\TaskAnalyzer.Tests.csproj --no-restore --verify-no-changes --include src\TaskAnalyzer.Tests\MultiThreadableTaskAnalyzerTests.cs src\TaskAnalyzer.Tests\TransitiveCallChainAnalyzerTests.cs src\TaskAnalyzer.Tests\PackageContractTests.cs — passed. The formatter emitted a workspace-load warning.
  • git diff --check — passed.

Unit tests cover MT scope, regular-task exclusions, migration opt-in, contributing bases, analyzed helpers, duplicate detection, independent severity settings, and call-site suppression.

The package test builds real consumers. It verifies regular-task builds with warnings as errors, migration opt-in, default MT warnings without an error log, and independent compiler severity settings. It also verifies explicit errors, NoWarn, warnings-as-errors exemptions, category settings, and resetting MSBuildTask0005 to its default.

The full repository test suite and other compiler/IDE host versions were not run.

Dependencies and Follow-up

No companion PR or merge-order dependency.

Redesigning or removing the transitive rule remains a separate follow-up under #14993. The 18.12 backport must be checked against that branch separately. This PR targets main and does not apply the backport.

Earlier proposals remain in branch history. This revision supersedes them without rewriting history.

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 and others added 2 commits October 9, 2026 15:04
Supersede the earlier proposal to remove MSBuildTask0005; retain its ID for the minimal severity fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6f7d76a8-bcea-4914-87bc-b40dc2e07be8
Keep MSBuildTask0004 informational and make MSBuildTask0005 inherit the originating rule's configured severity unless explicitly overridden. Preserve rule IDs, analysis scope, and call-site suppressions; verify warnings-as-errors package consumers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6f7d76a8-bcea-4914-87bc-b40dc2e07be8
@VolPlita VolPlita changed the title Vplita transitive violations Fix TaskAnalyzer review and transitive diagnostic severities Oct 9, 2026
@VolPlita
VolPlita marked this pull request as ready for review October 9, 2026 13:51
Copilot AI balanced review requested due to automatic review settings October 9, 2026 13:51
@VolPlita
VolPlita temporarily deployed to copilot-pat-pool October 9, 2026 13:51 — with GitHub Actions Inactive
@VolPlita
VolPlita temporarily deployed to copilot-pat-pool October 9, 2026 13:51 — with GitHub Actions Inactive
@VolPlita
VolPlita temporarily deployed to copilot-pat-pool October 9, 2026 13:52 — with GitHub Actions Inactive

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.

🟡 Changes recommended

Severity resolution does not consistently follow Roslyn’s command-line and explicit-default precedence rules.

1 open finding
What changed in this PR

Aligns TaskAnalyzer severities with compatibility-safe defaults while preserving configurable enforcement.

Changes:

  • Lowers MSBuildTask0004 to Info.
  • Makes MSBuildTask0005 inherit originating-rule severity.
  • Updates documentation, release metadata, and regression/package tests.
File Description
src/​TaskAnalyzer/​TransitiveCallChainAnalyzer.cs Implements transitive severity inheritance.
src/​TaskAnalyzer/​SharedAnalyzerHelpers.cs Shares category-to-descriptor mapping.
src/​TaskAnalyzer/​MultiThreadableTaskAnalyzer.cs Uses the shared mapping.
src/​TaskAnalyzer/​DiagnosticDescriptors.cs Lowers 0004/0005 descriptor defaults.
src/​TaskAnalyzer/​README.md Documents updated severity behavior.
src/​TaskAnalyzer/​AnalyzerReleases.Unshipped.md Records changed rule severities.
src/​TaskAnalyzer.Tests/​TransitiveCallChainAnalyzerTests.cs Tests inherited and configured severities.
src/​TaskAnalyzer.Tests/​MultiThreadableTaskAnalyzerTests.cs Tests 0004 Info defaults and overrides.
src/​TaskAnalyzer.Tests/​PackageContractTests.cs Validates packaged analyzer behavior.

🧠 Review effort: Balanced


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

@VolPlita
VolPlita temporarily deployed to copilot-pat-pool October 9, 2026 14:15 — with GitHub Actions Inactive
@VolPlita
VolPlita temporarily deployed to copilot-pat-pool October 9, 2026 14:16 — with GitHub Actions Inactive

@github-actions github-actions Bot 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.

# Dimension Verdict
4 Test Coverage & Completeness 🟡 1 MAJOR

✅ 23/24 dimensions clean.

  • Test Coverage & Completeness — package-contract assertions verify diagnostic IDs but not the configured warning severity.

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com
  • patchdiff.githubusercontent.com
  • raw.githubusercontent.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"
    - "patchdiff.githubusercontent.com"
    - "raw.githubusercontent.com"

See Network Configuration for more information.

Generated by Expert Code Review (on open) for #14777 · copilot · gpt56 · 1.3K AIC · ⌖ 0.507 AIC · ⊞ 24.9K

Comments that could not be inline-anchored

src/TaskAnalyzer.Tests/PackageContractTests.cs:203

[MAJOR] Test Coverage & Completeness

This package-consumption regression can still pass if the explicit warning settings are ignored and both diagnostics remain Info: the output still contains MSBuildTask0004 and MSBuildTask0005, so these ID-only assertions do not prove that packaged analyzer configuration restored warning severity. For example, changing both test settings to suggestion would satisfy the current assertions.

Recommendation: Assert warning MSBuildTask0004 an…

@VolPlita
VolPlita temporarily deployed to copilot-pat-pool October 9, 2026 14:17 — with GitHub Actions Inactive
Use Roslyn filtering for originating severity, compiler precedence, default resets and source suppressions. Preserve warning exemptions and schedule the analyzer even with informational defaults. Cover real compiler and bulk-configuration cases, and document the approved DiagnosticSuppressor limitation for frozen exemptions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6f7d76a8-bcea-4914-87bc-b40dc2e07be8
@VolPlita VolPlita changed the title Fix TaskAnalyzer review and transitive diagnostic severities Fix TaskAnalyzer review defaults and inherit effective transitive severity Oct 11, 2026
@VolPlita
VolPlita requested review from AR-May and a balanced review from Copilot October 11, 2026 16:17

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.

🔵 Needs a closer look

Manual Roslyn severity-precedence handling affects build-breaking diagnostics across compiler hosts not covered by validation.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Replace effective-severity inheritance with existing MT scope checks. Preserve explicit migration analysis and fix direct/transitive deduplication for regular task helpers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4ec658bb-dbe1-4204-a5fe-d343a4520eb3
@VolPlita VolPlita changed the title Fix TaskAnalyzer review defaults and inherit effective transitive severity Limit TaskAnalyzer review and transitive warnings to MT-scoped tasks Oct 13, 2026
### MSBuildTask0005 — Transitive Unsafe API Usage

MSBuildTask0001–MSBuildTask0004 only look at code written inside a task class — or inside a helper explicitly opted in with `[MSBuildMultiThreadableTaskAnalyzed]` (see [Analysis Scope](#analysis-scope)). MSBuildTask0005 closes that gap: it builds a compilation-wide call graph and walks it from each task's members. Transitive MSBuildTask0001/0004 violations are reported for every task; transitive MSBuildTask0002/0003 violations follow the configured migration option.
MSBuildTask0001–MSBuildTask0004 check task classes, explicitly analyzed helpers, and contributing source base classes (see [Analysis Scope](#analysis-scope)). MSBuildTask0005 also checks other helpers through a compilation-wide call graph. By default, it reports unsafe calls reached from MT-scoped tasks. All-task migration analysis enables these findings for regular tasks too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this became less clear than the previous version

.ShouldBe(ReadBytes(frameworkPackage, frameworkPackage.NuspecReader.GetIcon()));
}

private async Task VerifyExplicitPackageReferenceActivatesAnalyzer(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test grew significantly in scope and now it is difficult to follow its intent. I advice dropping some of the verifications or breaking into smaller more focused tests. I also think the most of it is not needed as we abandoned the inheritance of the severity.

[Theory]
[InlineData("", "#pragma warning disable MSBuildTask0001")]
[InlineData("[System.Diagnostics.CodeAnalysis.SuppressMessage(\"MSBuild.TaskAuthoring\", \"MSBuildTask0001\")]", "")]
public async Task TransitiveDiagnostic_DoesNotInheritOriginatingSourceSuppression(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is unclear what test does from this name. Better suited name is "TransitiveDiagnostic_MSBuildTask0005_IsNotSuppressedByMSBuildTask0001Suppression"

[InlineData("", DiagnosticSeverity.Hidden)]
[InlineData("suggestion", DiagnosticSeverity.Info)]
[InlineData("default", DiagnosticSeverity.Warning)]
public async Task TransitiveDiagnostic_GlobalConfigSeverity_CanBeOverriddenAtCallSite(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test checks Roslyn’s configuration behavior, rather than analyzers logic

}

[Fact]
public async Task MSBuildTask0004_AnalyzedHelperAndContributingBase_ReportDirectlyWithoutDuplicates()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MSBuildTask0004_AnalyzedHelperAndContributingBase_Report0004WithoutDuplicate0005?

[Theory]
[InlineData("suggestion", DiagnosticSeverity.Info)]
[InlineData("warning", DiagnosticSeverity.Warning)]
public async Task MSBuildTask0004_ConfiguredSeverity_OverridesWarningDefault(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This mostly verifies standard Roslyn severity handling, not the anayzer logic

@AR-May AR-May left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Decided to address the tests and docs in the follow up if needed.

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.

3 participants