Skip to content

Fix dotnet format forwarding under NativeAOT - #55920

Merged
baronfel merged 4 commits into
mainfrom
copilot/fix-dotnet-format-forwarding
Aug 25, 2026
Merged

baronfel merged 4 commits into
mainfrom
copilot/fix-dotnet-format-forwarding

Conversation

Copilot AI commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

dotnet format could resolve its bundled tool path from the muxer/install root under NativeAOT, causing forwarding to fail because dotnet-format.dll lives in the versioned SDK directory.

  • Path resolution
    • Resolve dotnet-format dll, deps, and runtimeconfig paths from SdkPaths.SdkDirectory.
    • Avoid using AppContext.BaseDirectory for SDK-relative DotnetTools assets.
Path.Combine(SdkPaths.SdkDirectory, "DotnetTools/dotnet-format/dotnet-format.dll")
  • Regression coverage
    • Add an AOT-focused test that sets the SDK root AppContext value and verifies forwarded dotnet-format paths use that SDK directory.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI linked an issue Aug 25, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix dotnet format forwarding broken with aot Fix dotnet format forwarding under NativeAOT Aug 25, 2026
Copilot AI requested a review from baronfel August 25, 2026 13:17
@baronfel
baronfel marked this pull request as ready for review August 25, 2026 13:58
Copilot AI lite review requested due to automatic review settings August 25, 2026 13:58
@baronfel
baronfel requested a review from a team as a code owner August 25, 2026 13:58
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@baronfel

Copy link
Copy Markdown
Member

We'll need to backport this to the release branches.

@baronfel
baronfel requested review from a team August 25, 2026 13:59
@baronfel
baronfel enabled stacked auto-merge (squash) August 25, 2026 14:06

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

Fixes dotnet format forwarding under the NativeAOT host by resolving dotnet-format tool assets from the versioned SDK directory (via SdkPaths.SdkDirectory) instead of AppContext.BaseDirectory, which can point at the muxer/install root in AOT scenarios.

Changes:

  • Update FormatForwardingApp to build the forwarded DLL/deps/runtimeconfig paths from SdkPaths.SdkDirectory.
  • Add a NativeAOT-focused regression test that sets the SDK root AppContext value and asserts the forwarded dotnet format invocation uses that SDK directory.

Reviewed changes

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

File Description
src/Cli/dotnet/Commands/Format/FormatForwardingApp.cs Switches forwarded dotnet-format asset path resolution to SdkPaths.SdkDirectory to work correctly under NativeAOT.
test/dotnet-aot.Tests/FormatForwardingAppTests.cs Adds regression coverage ensuring forwarded args use the AppContext-provided SDK directory.

Comment on lines +12 to +19
private readonly struct SdkDirectoryScope : IDisposable
{
private readonly object? _previousSdkRoot = AppContext.GetData(SdkPaths.DataName);

public SdkDirectoryScope(string sdkDirectory)
{
AppContext.SetData(SdkPaths.DataName, sdkDirectory);
SdkPaths.ClearSdkDirectoryCacheForTests();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the helper into a single shared test/dotnet-aot.Tests/SdkDirectoryScope.cs and removed both local copies in 00edfd1.

stacked auto-merge was automatically disabled August 25, 2026 14:22

Head branch was pushed to by a user without write access

Copilot AI requested a review from baronfel August 25, 2026 14:23
@baronfel

Copy link
Copy Markdown
Member

@copilot the implementation leads to mixed-slashes on paths on windows. evaluate and fix please.

Copilot AI commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the implementation leads to mixed-slashes on paths on windows. evaluate and fix please.

Fixed in eca98f4 — the DotnetTools/dotnet-format/... literal is now passed as separate Path.Combine segments, so the separators match the platform instead of mixing \ and / on Windows.

@baronfel baronfel added Area-dotnet AOT Items that are part of the dotnet CLI AOT-ification effort Area-Format labels Aug 25, 2026
@baronfel
baronfel merged commit 710aae6 into main Aug 25, 2026
23 checks passed
@baronfel
baronfel deleted the copilot/fix-dotnet-format-forwarding branch August 25, 2026 21:52
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-dotnet AOT Items that are part of the dotnet CLI AOT-ification effort Area-Format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet format forwarding is broken with aot

4 participants