Conversation
Contributor
|
Hello @copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
…MT tasks Co-authored-by: VolPlita <95765929+VolPlita@users.noreply.github.com>
Co-authored-by: VolPlita <95765929+VolPlita@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update TaskAnalyzer to report MT diagnostics as suggestions for non-MT tasks
TaskAnalyzer: report MT migration diagnostics as suggestions for non-MT tasks
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue(s):
Context
MT-related TaskAnalyzer diagnostics are useful migration guidance for every task, but reporting them as warnings on tasks that are not adopting multithreaded execution disrupts those builds. Previously the analyzer resolved this by suppressing MSBuildTask0002/0003 (and the MSBuildTask0005 findings carrying them) entirely outside MT-scoped code, so authors got no guidance at all unless they opted into full enforcement.
These diagnostics are now reported for all tasks, at a severity chosen from the task context:
Info/Suggestion for non-MT tasks, unchangedWarningfor MT-scoped code.Changes Made
SharedAnalyzerHelpers):CreateWithContextualSeverityreports a diagnostic atdescriptor.DefaultSeverityfor MT-scoped code and atMigrationGuidanceSeverity(Info) elsewhere. The diagnostic ID is unchanged, and the compiler appliesdotnet_diagnostic.<ID>.severityafter the analyzer reports, so an explicit setting still wins in both directions.MultiThreadableTaskAnalyzer): the scope checkShouldReportEnvironmentRulesbecameShouldEnforceEnvironmentRules— it now selects severity instead of gating the report.TransitiveCallChainAnalyzer): transitive MT migration violations use the same contextual severity.IsReportedByDirectAnalyzerbecameGetDirectAnalyzerCoverage, returningNone/Guidance/Full, so a call the direct analyzer already surfaces as a suggestion is not repeated as MSBuildTask0005 on the same call site, while an MT caller still gets the full-severity chain diagnostic through the same helper.run_mt_analyzers_on_all_tasksinteraction: unchanged as the opt-in for full enforcement — whentrue, all tasks report atWarning; when absent orfalse, non-MT tasks report atInfo.Compatibility
Non-MT tasks that previously saw no MSBuildTask0002/0003/0005 migration diagnostics now see them as
Info. This is visible in IDE and-v:detailedoutput but does not affect build success, including under/WarnAsError. MT-scoped severity,run_mt_analyzers_on_all_taskssemantics, and explicitdotnet_diagnostic.<ID>.severityconfiguration are unchanged. The MSBuildTask0002/0003 code fixes already withhold themselves where aTaskEnvironmentreference would not compile, so they remain safe on tasks that now receive suggestions.Testing
dotnet test src/TaskAnalyzer.Tests/TaskAnalyzer.Tests.csproj— 365 passing. Existing tests that asserted absence for non-MT tasks were converted to assertInfoseverity; new tests cover MT-scopedWarning,run_mt_analyzers_on_all_tasks = trueraising non-MT tasks toWarning,dotnet_diagnostic.MSBuildTask0002.severity = errorraising a non-MT suggestion,= suggestionlowering an MT warning,= nonesuppressing both 0002 and 0003, and an explicit override on transitive MSBuildTask0005.dotnet msbuild src/Tasks/Microsoft.Build.Tasks.csproj -p:BuildAnalyzer=true -t:Rebuildproduces the same diagnostics as before —src/Tasks/TaskAnalyzer.globalconfigsetsrun_mt_analyzers_on_all_tasks = true, so that build stays on full enforcement.Dependencies and Follow-up
Open design point for reviewers: whether any diagnostics beyond MSBuildTask0002/0003 and the MSBuildTask0005 findings that carry them should also use contextual severity.