Repository navigation
Limit TaskAnalyzer review and transitive warnings to MT-scoped tasks - #14777
Conversation
…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>
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
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
| # | 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.comgithub.zerozr99.workers.devpatchdiff.githubusercontent.comraw.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-proxySee 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…
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
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
| ### 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. |
There was a problem hiding this comment.
nit: this became less clear than the previous version
| .ShouldBe(ReadBytes(frameworkPackage, frameworkPackage.NuspecReader.GetIcon())); | ||
| } | ||
|
|
||
| private async Task VerifyExplicitPackageReferenceActivatesAnalyzer( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
This test checks Roslyn’s configuration behavior, rather than analyzers logic
| } | ||
|
|
||
| [Fact] | ||
| public async Task MSBuildTask0004_AnalyzedHelperAndContributingBase_ReportDirectlyWithoutDuplicates() |
There was a problem hiding this comment.
MSBuildTask0004_AnalyzedHelperAndContributingBase_Report0004WithoutDuplicate0005?
| [Theory] | ||
| [InlineData("suggestion", DiagnosticSeverity.Info)] | ||
| [InlineData("warning", DiagnosticSeverity.Warning)] | ||
| public async Task MSBuildTask0004_ConfiguredSeverity_OverridesWarningDefault( |
There was a problem hiding this comment.
This mostly verifies standard Roslyn severity handling, not the anayzer logic
AR-May
left a comment
There was a problem hiding this comment.
Decided to address the tests and docs in the follow up if needed.

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
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.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 = defaultsetting 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, withMSBUILDUSESERVER=0andMSBUILDDISABLENODEREUSE=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.call artifacts\msbuild-build-env.bat,dotnet --version— passed:11.0.100-rc.1.26420.103.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 MSBuild18.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.