Skip to content

Onboard MSBuild task projects to Microsoft.Build.TaskAuthoring.Analyzer (report-only) - #54979

Merged
baronfel merged 4 commits into
mainfrom
baronfel-taskauthoring-analyzer-onboarding
Jun 25, 2026
Merged

baronfel merged 4 commits into
mainfrom
baronfel-taskauthoring-analyzer-onboarding

Conversation

@baronfel

@baronfel baronfel commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

What

Onboards the repo to the Microsoft.Build.TaskAuthoring.Analyzer (the MSBuild thread-safe task analyzer) and applies it to the 12 projects that contain MSBuild task implementations, in report-only mode. The repo builds green (0 errors, 0 warnings); every analyzer finding surfaces as an info-level suggestion.

This is the first step toward getting SDK's MSBuild Tasks 'green' from an analyzer perspective. Follow-up PRs can then tackle one task class — or one diagnostic category — at a time by raising severity in .editorconfig.

Mechanism (centralized + opt-in)

  • Directory.Packages.props — pins the analyzer (18.9.0-preview-26310-106, dotnet-eng feed).
  • eng/MSBuildTaskAuthoringAnalyzer.props (new) — adds the analyzer as an analyzers-only PackageReference (PrivateAssets="all" IncludeAssets="analyzers") for any project that opts in with IsMSBuildTaskProject=true (excluded in source-only builds). Imported from Directory.Build.targets.
  • 12 task .csproj files — each opts in via <IsMSBuildTaskProject>true</IsMSBuildTaskProject>.
  • .editorconfig — downgrades MSBuildTask0001–0005 to suggestion. At info severity the diagnostics are never promoted to warnings/errors — not even by the MSBuild engine's warn-as-error (MSBuildTreatWarningsAsErrors) that Arcade enables — so no WarningsNotAsErrors exemption lists are needed.
  • src/StaticWebAssetsSdk/.editorconfig — carries its own copy of the suggestion block because it sets root = true and so does not inherit the repo-root .editorconfig. It's the only one of the 12 task projects with a root = true editorconfig.

Diagnostics

The analyzer raises 373 unique findings across 11 projects (Microsoft.DotNet.GenAPI.Task is clean):

Rule Count Meaning
MSBuildTask0002 49 API needs a TaskEnvironment alternative (env vars, CWD, Path.GetFullPath, Process.Start)
MSBuildTask0003 268 File-system API needs an absolutized path
MSBuildTask0005 56 Transitive unsafe usage in a task call chain

Top projects: StaticWebAssets.Tasks (144), sdk-tasks (86), Publish.Tasks (51), Build.Tasks (43).

A full report (per-rule / per-project / per-file breakdown) is attached to the tracking work.

Re-enablement path (follow-up PRs)

  • Per category: raise a single dotnet_diagnostic.MSBuildTask000X.severity to warning/error in the root .editorconfig (and the StaticWebAssets copy) once that rule is repo-wide clean.
  • Per task class: add/edit an .editorconfig in that task's source directory raising severity, then migrate that class to IMultiThreadableTask / TaskEnvironment.

Validation

build.cmd → Build succeeded, 0 errors, 0 warnings. No .xlf changes; no new NETSDK error codes.

Adds the Microsoft.Build.TaskAuthoring.Analyzer (the MSBuild thread-safe task
analyzer) to the 12 projects that contain MSBuild task implementations, in
report-only mode so the repo keeps building green while the multithreaded-task
migration is staged across follow-up PRs.

Mechanism (centralized + opt-in):
- Directory.Packages.props: pin the analyzer (18.9.0-preview-26310-106).
- eng/MSBuildTaskAuthoringAnalyzer.props (new): adds the analyzer as an
  analyzers-only PackageReference for projects that set IsMSBuildTaskProject=true
  (excluded in source-only builds). Imported from Directory.Build.targets.
- 12 task .csproj files opt in via <IsMSBuildTaskProject>true</IsMSBuildTaskProject>.
- .editorconfig downgrades MSBuildTask0001-0005 to suggestion (info level), which
  keeps the build green without any warnings-as-errors exemptions. StaticWebAssetsSdk
  sets root = true, so its .editorconfig carries its own copy of the block.

This surfaces 373 unique findings (MSBuildTask0002/0003/0005) across 11 projects;
follow-up PRs can raise severity per diagnostic category or per task class via
.editorconfig and migrate those tasks to IMultiThreadableTask / TaskEnvironment.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 25, 2026 15:00
@baronfel
baronfel requested review from a team and tmat as code owners June 25, 2026 15:00
@baronfel
baronfel requested a review from a team June 25, 2026 15:00
@baronfel
baronfel requested review from a team and vijayrkn as code owners June 25, 2026 15:00

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

Onboards dotnet/sdk MSBuild task projects to the Microsoft.Build.TaskAuthoring.Analyzer in report-only mode, so task thread-safety findings are surfaced without breaking builds. This lays groundwork for incremental migration to MSBuild’s multithreaded task model (IMultiThreadableTask / TaskEnvironment).

Changes:

  • Add a centralized opt-in mechanism (IsMSBuildTaskProject=true) that injects the analyzer as analyzers-only and skips source-only builds.
  • Pin the analyzer version via central package management.
  • Configure analyzer severities in .editorconfig (and a duplicated block under src/StaticWebAssetsSdk due to root = true), and opt 12 task projects into analysis.

Reviewed changes

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

Show a summary per file
File Description
src/WebSdk/Publish/Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj Opts the publish tasks project into the analyzer via IsMSBuildTaskProject.
src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.Tasks/Microsoft.TemplateEngine.Authoring.Tasks.csproj Opts template authoring tasks into the analyzer.
src/Tasks/sdk-tasks/sdk-tasks.csproj Opts sdk-tasks into the analyzer.
src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj Opts build tasks into the analyzer.
src/Tasks/Microsoft.NET.Build.Extensions.Tasks/Microsoft.NET.Build.Extensions.Tasks.csproj Opts build extensions tasks into the analyzer.
src/StaticWebAssetsSdk/Tasks/Microsoft.NET.Sdk.StaticWebAssets.Tasks.csproj Opts static web assets tasks into the analyzer.
src/StaticWebAssetsSdk/.editorconfig Adds a local severity override block because this editorconfig is root = true.
src/RazorSdk/Tasks/Microsoft.NET.Sdk.Razor.Tasks.csproj Opts Razor tasks into the analyzer.
src/Dotnet.Watch/DotNetWatchTasks/DotNetWatchTasks.csproj Opts dotnet-watch tasks into the analyzer.
src/Containers/Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj Opts container-related tasks into the analyzer.
src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI.Task/Microsoft.DotNet.GenAPI.Task.csproj Opts GenAPI task project into the analyzer.
src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Task/Microsoft.DotNet.ApiCompat.Task.csproj Opts ApiCompat task project into the analyzer.
src/BlazorWasmSdk/Tasks/Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.csproj Opts Blazor WASM tasks into the analyzer.
eng/MSBuildTaskAuthoringAnalyzer.props Implements the opt-in + analyzers-only PackageReference, excluded for source-only builds.
Directory.Packages.props Pins Microsoft.Build.TaskAuthoring.Analyzer package version centrally.
Directory.Build.targets Imports the opt-in analyzer props for all projects.
.editorconfig Sets repo-wide severities for MSBuildTask0001-0005 (note: currently uses silent, see PR comment).

Comment thread .editorconfig Resolved
@baronfel
baronfel requested review from a team and removed request for a team, tmat and vijayrkn June 25, 2026 15:03
Comment thread Directory.Packages.props Resolved
Comment thread eng/MSBuildTaskAuthoringAnalyzer.props Resolved
baronfel and others added 2 commits June 25, 2026 12:26
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…ncy flow

Per review feedback, the analyzer is now wired up as a package dependency
in eng/Version.Details.xml so the version produced by the msbuild repo
(via dotnet/dotnet) flows to the sdk repo, instead of being hardcoded in
Directory.Packages.props. The package already exists at the current
Microsoft.Build flow version (18.9.0-preview-26311-113), so no MSBuild
dependency bump is needed. Because it now flows through source build, the
DotNetBuildSourceOnly guard is removed from the onboarding props.

Co-authored-by: Copilot <[email protected]>
@baronfel

Copy link
Copy Markdown
Member Author

Wired the analyzer up as a package dependency per the package-dependency-flow guidance:

  • Added a Microsoft.Build.TaskAuthoring.Analyzer <Dependency> to eng/Version.Details.xml pointing at dotnet/dotnet (same Uri/Sha as the other Microsoft.Build.* packages), with a matching MicrosoftBuildTaskAuthoringAnalyzerPackageVersion in eng/Version.Details.props. Directory.Packages.props now references that property instead of a hardcoded version.
  • No MSBuild dependency bump was needed. The analyzer already publishes at 18.9.0-preview-26311-113 — the exact version Microsoft.Build currently flows — so the analyzer version stays coherent with the rest of the MSBuild packages automatically.
  • Since it now flows through the VMR (msbuild builds before sdk), I removed the DotNetBuildSourceOnly guard from eng/MSBuildTaskAuthoringAnalyzer.props so the analyzer runs in source build too.

Full build.cmd is green (0 warnings, 0 errors). Source-build CI is the real validator for the guard removal — happy to keep the DO-NOT-MERGE label until that's confirmed. Let me know if you'd like anything else adjusted.

@baronfel
baronfel requested a review from mthalman June 25, 2026 19:23
@baronfel
baronfel enabled auto-merge (squash) June 25, 2026 19:37
@baronfel
baronfel merged commit ed3ff8d into main Jun 25, 2026
25 checks passed
@baronfel
baronfel deleted the baronfel-taskauthoring-analyzer-onboarding branch June 25, 2026 19:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants