Skip to content

Enable MSBuildTask0001 task-authoring analyzer at error severity#55053

Open
baronfel wants to merge 2 commits into
mainfrom
baronfel-refactored-winner
Open

Enable MSBuildTask0001 task-authoring analyzer at error severity#55053
baronfel wants to merge 2 commits into
mainfrom
baronfel-refactored-winner

Conversation

@baronfel

Copy link
Copy Markdown
Member

Summary

The Microsoft.Build.TaskAuthoring.Analyzer (MSBuild thread-safe task analyzer) was recently referenced from all IsMSBuildTaskProject projects, but every rule (MSBuildTask0001–0005) was downgraded to suggestion for report-only onboarding. This PR takes one rule and fully re-enables it across the codebase as an example of the incremental ratcheting workflow.

What changed

  • Re-enabled MSBuildTask0001 at its natural error severity in both the repo-root .editorconfig and src/StaticWebAssetsSdk/.editorconfig (the latter sets root = true, so it keeps its own in-sync copy). Rules 0002–0005 remain at suggestion.
  • Fixed the only banned-API call site in task code paths: ContainerBuilder.cs called Console.WriteLine(...) on an error path; replaced it with logger.LogError(Resource.FormatString(...)), matching the surrounding error-handling pattern.

Why MSBuildTask0001 first

MSBuildTask0001 flags APIs that are never safe in any MSBuild task (Console.*, Environment.Exit/FailFast, Process.Kill, Directory.SetCurrentDirectory, ThreadPool.SetMin/MaxThreads, CultureInfo.DefaultThreadCurrent*). Crucially, its fixes (e.g. Console.*Log.LogMessage) do not depend on the IMultiThreadableTask / TaskEnvironment migration that rules 0002/0003 require — so it can be enabled today without any task rewrites.

Verification

  • Confirmed via binlog that the analyzer loads and runs in task projects.
  • Proved the promotion is effective: a temporarily injected Console.WriteLine in a real task class produced error MSBuildTask0001 (then reverted).
  • Built all 12 IsMSBuildTaskProject projects — every one succeeds with zero MSBuildTask0001 diagnostics.

Follow-ups

The same one-rule-at-a-time pattern can be repeated for MSBuildTask0002–0005 as tasks migrate to IMultiThreadableTask / TaskEnvironment.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Re-enable the Microsoft.Build.TaskAuthoring.Analyzer MSBuildTask0001 rule (never-safe APIs such as Console.*, Environment.Exit/FailFast, Process.Kill, Directory.SetCurrentDirectory) at its natural 'error' severity, as the first incremental step out of the report-only 'suggestion' onboarding. Its fixes do not depend on the IMultiThreadableTask/TaskEnvironment migration that 0002-0005 require.

Updated both the repo-root .editorconfig and src/StaticWebAssetsSdk/.editorconfig (root=true, keeps its own copy). Fixed the only banned-API call site in task code paths: ContainerBuilder.cs used Console.WriteLine on an error path; switched to logger.LogError. All 12 IsMSBuildTaskProject projects build green with the rule at error.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 15:26
@baronfel baronfel requested a review from a team June 29, 2026 15:28

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

This PR incrementally ratchets up enforcement of the MSBuild task-authoring analyzer by promoting MSBuildTask0001 back to its default error severity, and fixes the only known task-path call site that violated the rule by removing a Console.WriteLine usage in container task code.

Changes:

  • Re-enabled dotnet_diagnostic.MSBuildTask0001.severity = error in the repo-root .editorconfig.
  • Kept src/StaticWebAssetsSdk/.editorconfig (which sets root = true) in sync by re-enabling MSBuildTask0001 there as well.
  • Replaced a Console.WriteLine(...) error-path call in ContainerBuilder with logger.LogError(Resource.FormatString(...)).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/StaticWebAssetsSdk/.editorconfig Re-enables MSBuildTask0001 at error severity while keeping 0002–0005 at suggestion, with updated onboarding commentary.
src/Containers/Microsoft.NET.Build.Containers/ContainerBuilder.cs Removes Console.WriteLine on an error path to comply with MSBuildTask0001, using existing logging/resource formatting patterns.
.editorconfig Promotes MSBuildTask0001 to error severity globally while leaving 0002–0005 as suggestion, with expanded rationale/comments.

Comment thread src/Containers/Microsoft.NET.Build.Containers/ContainerBuilder.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

2 participants