Skip to content

Fix TaskAnalyzer path-resolution order and detect inverted compositions - #14972

Draft
ViktorHofer with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-inverted-composition-diagnosis
Draft

Fix TaskAnalyzer path-resolution order and detect inverted compositions#14972
ViktorHofer with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-inverted-composition-diagnosis

Conversation

Copilot AI commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Work item (Internal use):

Summary

MSBuildTask0003 can generate GetAbsolutePath(Path.GetDirectoryName(path)), which throws for bare filenames. Existing inverted calls also go undiagnosed.

  • Fixer: Resolve the original input before GetDirectoryName/GetPathRoot, including nested extractions.
  • Analyzer: Add scope-aware MSBuildTask0015 with a swap fix; recognize root extraction from absolute paths as safe.
Directory.CreateDirectory(
    Path.GetDirectoryName(TaskEnvironment.GetAbsolutePath(TargetFile)));

Customer Impact

Prevents migration-generated ArgumentException for inputs such as "list.xml" and identifies previously accepted inverted calls.

Regression?

Existing analyzer/fixer gap, not a runtime regression.

Testing

Regression coverage for both extraction methods, aliases, named arguments, nested calls, nullable inputs, scope, lookalike methods, and Fix All.

Risk

Limited to the unshipped, opt-in analyzer; no runtime changes. The new warning honors existing scope settings. Fixes are withheld where swapping would break AbsolutePath consumers or introduce nullable-input warnings.

@dotnet-policy-service

Copy link
Copy Markdown
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.

Copilot AI and others added 2 commits September 7, 2026 19:12
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code fix generating inverted composition in TaskAnalyzer Fix TaskAnalyzer path-resolution order and detect inverted compositions Sep 7, 2026
Copilot AI requested a review from ViktorHofer September 7, 2026 19:24
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.

TaskAnalyzer: code fix generates GetAbsolutePath(Path.GetDirectoryName(x)) and no diagnostic flags the inverted composition

2 participants