Skip to content

Recognize AbsolutePath.Value canonicalization in task analyzers - #14970

Merged
ViktorHofer merged 2 commits into
mainfrom
janprovaznik-taskanalyzer-arcade-investigation
Sep 8, 2026
Merged

ViktorHofer merged 2 commits into
mainfrom
janprovaznik-taskanalyzer-arcade-investigation

Conversation

@JanProvaznik

Copy link
Copy Markdown
Member

Fixes #14955

Context

Path.GetFullPath(absolutePath.Value) canonicalizes an already fully qualified value; it does not resolve a relative path against the process working directory. This is the underlying BCL operation used by MSBuild itself. AbsolutePath.GetCanonicalForm() returns:

return new AbsolutePath(System.IO.Path.GetFullPath(Value), OriginalValue, ignoreRootedCheck: true);

The analyzer already accepts native GetCanonicalForm() results through their AbsolutePath type. However, writing the normalization directly in a task produces MSBuildTask0002, and writing it in a source polyfill/helper produces MSBuildTask0005. This prevents downlevel consumers such as Arcade from implementing the operation without suppression.

The exception belongs at Path.GetFullPath(AbsolutePath.Value), not at a helper named GetCanonicalForm.

Changes Made

  • Share recognition of the one-argument BCL Path.GetFullPath call over the resolved Microsoft.Build.Framework.AbsolutePath instance string Value property between direct and transitive analysis.
  • Preserve the normalized result's absolute-path proof for MSBuildTask0003 consumers.
  • Resolve BCL Path through the intrinsic string type's assembly, rejecting source-defined and aliased-metadata lookalikes rather than comparing display names.
  • Cover both scopes, identity casts, nullable path access, aliases/named arguments, extension/static helper calls, and downstream I/O.
  • Keep diagnostics for OriginalValue, unrelated Value properties, unproven/reassigned strings, transformed inputs, and other overloads. No helper name whitelist or general-purpose dataflow exemption is added.
  • Document the narrow exception.

Testing

Built TaskAnalyzer.Tests.csproj and ran MultiThreadableTaskAnalyzerTests, TransitiveCallChainAnalyzerTests, and MultiThreadableTaskCodeFixProviderTests: 143 passed, zero failed or skipped.

Used Arcade as the real-project reproduction at f1ce2c65fd8036c495df221b7257e2680e15b4a2, retaining its Framework/Utilities 18.8.2 references and existing multithreadable_only configuration. Rebuilt the actual Templating project using isolated variants of GenerateFileFromTemplate, with I/O rooted and retained as AbsolutePath. A compile-item overlay kept the original Arcade snapshot unchanged.

Real Arcade task variant Before After
Direct Path.GetFullPath(outputPath.Value) One MSBuildTask0002 No TaskAnalyzer diagnostics
Same operation inside GetCanonicalForm extension One MSBuildTask0005 No TaskAnalyzer diagnostics

No suppressions or broad-scope overrides were used. Compiler logs confirm the 18.8.2 references and the locally built analyzer. Both variants were rebuilt after tightening BCL symbol identity.

Notes

  • Red-team review found the initial type-name comparison could accept a user-defined System.IO.Path. This was fixed and covered for source and referenced lookalikes; the follow-up review found no remaining actionable or blocking issues.
  • This only removes false positives under the existing AbsolutePath contract. It adds no runtime/API changes, diagnostic IDs, or severity changes, so no ChangeWave is needed.
  • This is not a blanket Arcade migration or a promise of exact runtime parity for every downlevel polyfill. Older-host rooting behavior (fixed separately by Fix AbsolutePath.GetCanonicalForm process state leak on Windows  #13788) and preservation of OriginalValue remain separate compatibility concerns. No Arcade production changes are included.

Accept the same Path.GetFullPath sink used by AbsolutePath.GetCanonicalForm in direct and transitive task analysis, while retaining diagnostics for unproven inputs and lookalike APIs.

Co-authored-by: Copilot App <[email protected]>
Copilot AI lite review requested due to automatic review settings September 7, 2026 16:55

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.

🟢 Approval recommended

The change is narrowly scoped, well-documented, and covered by targeted tests across both direct and transitive analyzer paths.

Pull request overview

This PR updates the MSBuild task analyzers to recognize the specific canonicalization pattern Path.GetFullPath(absolutePath.Value) as equivalent to AbsolutePath.GetCanonicalForm() behavior, avoiding false positives in both direct (MSBuildTask0002) and transitive (MSBuildTask0005) analysis while still treating the resulting string as absolute for MSBuildTask0003.

Changes:

  • Add a narrowly-scoped exemption for Path.GetFullPath(AbsolutePath.Value) in both MultiThreadableTaskAnalyzer and TransitiveCallChainAnalyzer.
  • Teach the absolute-path proof logic (MSBuildTask0003) that this exact canonicalization yields a safe absolute string.
  • Document the exception and add unit tests covering safe/unsafe inputs and “lookalike” System.IO.Path scenarios.
File summaries
File Description
src/TaskAnalyzer/TransitiveCallChainAnalyzer.cs Skips recording a banned-API violation when the invocation matches the AbsolutePath canonicalization pattern.
src/TaskAnalyzer/SharedAnalyzerHelpers.cs Introduces IsAbsolutePathCanonicalization and uses it to treat the canonicalization result as safely absolute.
src/TaskAnalyzer/README.md Documents the new narrow canonicalization exception and its boundaries.
src/TaskAnalyzer/MultiThreadableTaskAnalyzer.cs Avoids reporting MSBuildTask0002/0004 for the canonicalization call when it matches the approved pattern.
src/TaskAnalyzer.Tests/TransitiveCallChainAnalyzerTests.cs Adds coverage ensuring polyfills/helpers performing canonicalization don’t trigger diagnostics and unsafe variants still do.
src/TaskAnalyzer.Tests/MultiThreadableTaskAnalyzerTests.cs Adds direct analyzer coverage for canonicalization, unsafe variants, and “lookalike Path” negative cases.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@ViktorHofer

Copy link
Copy Markdown
Member

I'm gonna merge this in so that I can consume an updated analyzer in arcade soon.

@ViktorHofer
ViktorHofer merged commit f5675f0 into main Sep 8, 2026
14 checks passed
@ViktorHofer
ViktorHofer deleted the janprovaznik-taskanalyzer-arcade-investigation branch September 8, 2026 10:09
This was referenced Nov 22, 2026
flxjk pushed a commit to flxjk/typespec that referenced this pull request Nov 25, 2026
Updated [Microsoft.Build](https://github.com/dotnet/msbuild) from
18.11.0 to 18.12.2.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Build's
releases](https://github.com/dotnet/msbuild/releases)._

## 18.12.2

## What's Changed
* [TaskAnalyzer] Align diagnostic severities and ignore open generic
ITaskItem<T> by @​VolPlita in
dotnet/msbuild#14811
* Add multi-threading option to build response file by @​ViktorHofer in
dotnet/msbuild#14837
* Anchor MSBuildTask0003 code fix on the flagged call and withhold it
where TaskEnvironment cannot bind by @​ViktorHofer with @​Copilot in
dotnet/msbuild#14810
* Bump main to 18.12 after the vs18.11 branch snap by @​ViktorHofer in
dotnet/msbuild#14841
* Report MSBuildTask0005 at the unsafe call site so it can be suppressed
there by @​ViktorHofer with @​Copilot in
dotnet/msbuild#14829
* Revert "Add multi-threading option to build response file" by
@​ViktorHofer in dotnet/msbuild#14851
* [main] Source code updates from dotnet/dotnet by @​dotnet-maestro[bot]
in dotnet/msbuild#14853
* [main] Update dependencies from dotnet/arcade by @​dotnet-maestro[bot]
in dotnet/msbuild#14854
* Update MicrosoftBuildVersion in analyzer template by
@​github-actions[bot] in dotnet/msbuild#14565
* Revert "Revert "Add multi-threading option to build response file"" by
@​ViktorHofer in dotnet/msbuild#14855
* Fix stale gh-aw-actions/setup pin causing "activation" job failure by
@​JanProvaznik with @​Copilot in
dotnet/msbuild#14842
* Make isolated graph builds fail deterministically on undeclared
cross-project targets by @​AlesProkop with @​Copilot in
dotnet/msbuild#14280
* Revise temp path handling in README by @​baronfel in
dotnet/msbuild#14834
* Fix BuildCheck rule configuration and task name casing bug by @​AR-May
in dotnet/msbuild#14778
* Remove MSBuildImportedProject item from the XSD by @​drewnoakes in
dotnet/msbuild#14659
* [main] Source code updates from dotnet/dotnet by @​dotnet-maestro[bot]
in dotnet/msbuild#14866
* Require ready-for-training tag for OptProf by @​AlesProkop in
dotnet/msbuild#14867
* Ignore stale MSBuild server console writes by @​JanProvaznik in
dotnet/msbuild#14850
* Regenerate Expert Code Review workflow lock by @​JanProvaznik with
@​Copilot in dotnet/msbuild#14870
* [main] Update dependencies from dotnet/arcade by @​dotnet-maestro[bot]
in dotnet/msbuild#14896
* [main] Update dependencies from dotnet/roslyn by @​dotnet-maestro[bot]
in dotnet/msbuild#14900
* [main] Update dependencies from nuget/nuget.client by
@​dotnet-maestro[bot] in dotnet/msbuild#14669
* [main] Source code updates from dotnet/dotnet by @​dotnet-maestro[bot]
in dotnet/msbuild#14886
* Expose AbsolutePath.GetCanonicalForm() by @​JanProvaznik with
@​Copilot in dotnet/msbuild#14873
* Make release checklist step 1.3 a full branch-retirement audit by
@​ViktorHofer in dotnet/msbuild#14911
* Resolve PathLike MatchOnMetadata against the thread working directory
by @​JanProvaznik in dotnet/msbuild#14916
* Fix typo in project dependency explanation by @​DanexisIbrahimAbtula
in dotnet/msbuild#14885
* Preserve events routed through the TaskHostTask by @​AR-May in
dotnet/msbuild#14876
* Fix NormalizePath and other intrinsic functions in multithreaded mode
by @​AR-May in dotnet/msbuild#14875
* Bump actions/checkout from 7.0.0 to 7.0.1 by @​dependabot[bot] in
dotnet/msbuild#14887
* Bump github/gh-aw-actions/setup-cli from 0.87.2 to 0.87.9 by
@​dependabot[bot] in dotnet/msbuild#14888
* Bump github/gh-aw-actions/setup from 0.82.9 to 0.87.9 by
@​dependabot[bot] in dotnet/msbuild#14889
* Upgrade gh-aw to v0.88.2 and recompile agentic workflow lock files by
@​AR-May in dotnet/msbuild#14935
* Preserve error detail when ContinueOnError downgrades an error to a
warning by @​AR-May in dotnet/msbuild#14918
* Fix Dependabot ignore rule to match gh-aw-actions sub-path actions by
@​AR-May in dotnet/msbuild#14938
* [Flaky Test] Quarantine 1 flaky test (TaskEnvironment) by
@​github-actions[bot] in dotnet/msbuild#14662
* Fix template path in quarantine pipeline by @​AR-May in
dotnet/msbuild#14937
* Run expert code review when a draft PR is marked ready for review by
@​AR-May in dotnet/msbuild#14952
* [Dreaming] dreaming: clarify RenderImmediateMessage as the correct
path for immediate TerminalLogger output by @​github-actions[bot] in
dotnet/msbuild#14381
* [Dreaming] Clarify: don't hardcode backslash path separators in test
XML by @​github-actions[bot] in
dotnet/msbuild#14973
* Regenerate review-on-open lock file by @​AR-May in
dotnet/msbuild#14977
* Recognize AbsolutePath.Value canonicalization in task analyzers by
@​JanProvaznik in dotnet/msbuild#14970
* improve issue and pr templates based on history by @​JanProvaznik in
dotnet/msbuild#14982
* Detect environment-dependent temp helpers in TaskAnalyzer by
@​ViktorHofer with @​Copilot in
dotnet/msbuild#14975
* Document registered task object semantics in multithreaded builds by
@​JanProvaznik in dotnet/msbuild#14919
* Add server-only MSBUILDDEBUGONSTART modes by @​JanProvaznik in
dotnet/msbuild#14988
* Preserve manifest input streams when writing manifests by @​dtivel in
dotnet/msbuild#14883
* Scope MT-specific TaskAnalyzer diagnostics and support .editorconfig
by @​VolPlita in dotnet/msbuild#14775
* [main] Update dependencies from dotnet/arcade by @​dotnet-maestro[bot]
in dotnet/msbuild#14948
 ... (truncated)

Commits viewable in [compare
view](dotnet/msbuild@v18.11.0...v18.12.2).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Build&package-manager=nuget&previous-version=18.11.0&new-version=18.12.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@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.

Verify that the task analyzer understands and recommends the AbsolutePath.GetCanonicalForm API

3 participants