Skip to content

Only strip .exe/.dll when computing RootCommand.ExecutableName - #2855

Merged
adamsitnik merged 2 commits into
dotnet:mainfrom
adamsitnik:fix-executablename-dotted-names
Oct 12, 2026
Merged

adamsitnik merged 2 commits into
dotnet:mainfrom
adamsitnik:fix-executablename-dotted-names

Conversation

@adamsitnik

Copy link
Copy Markdown
Member

Starting with .NET 11 (dotnet/runtime#131671), Environment.GetCommandLineArgs()[0] is the name the apphost was invoked with. On Linux/macOS the apphost has no extension, so Path.GetFileNameWithoutExtension truncated dotted names (Contoso.Tool -> Contoso).

Only the known host extensions (.exe/.dll) are now stripped. The helper uses a span-based path on modern .NET to reduce allocations. Added unit tests.

Fixes #2850

On .NET 11, Environment.GetCommandLineArgs()[0] is the extensionless apphost
name on Linux/macOS, so Path.GetFileNameWithoutExtension truncated dotted
names (Contoso.Tool -> Contoso). Strip only known host extensions.

Fixes dotnet#2850

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3b277dd7-ee88-4838-8f41-724305913c08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The public XML documentation still describes the previous extension-removal behavior.

1 open finding
What changed in this PR

Updates executable-name resolution for .NET 11 apphosts while preserving dotted names.

Changes:

  • Strips only .exe and .dll suffixes.
  • Uses span-based processing on modern .NET.
  • Adds cross-platform unit coverage.
File Description
RootCommand.cs Uses the new executable-name helper.
ExecutableNameHelper.cs Implements selective extension removal.
System.CommandLine.Tests.csproj Links the helper into tests.
RootCommandTests.cs Tests dotted names, extensions, casing, and spaces.

🧠 Review effort: Balanced


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

Comment thread src/System.CommandLine/RootCommand.cs Resolved
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3b277dd7-ee88-4838-8f41-724305913c08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation directly addresses the regression with compatible behavior and focused tests.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@adamsitnik
adamsitnik enabled auto-merge (squash) October 12, 2026 09:40
@adamsitnik
adamsitnik merged commit d06ff71 into dotnet:main Oct 12, 2026
9 checks passed
@adamsitnik
adamsitnik deleted the fix-executablename-dotted-names branch October 12, 2026 16:19
@adamsitnik

Copy link
Copy Markdown
Member Author

@mmitche I need to backport this PR to .NET 11 RTM. Which branch should I use? release/11.0? Or are you going to create release/11.0-rtm?

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.

RootCommand.ExecutableName truncates dotted app names on Linux/macOS when targeting .NET 11

3 participants