Skip to content

Lazy initialize Spectre.Console in XPlat command registration#7063

Merged
zivkan merged 1 commit intodevfrom
dev-zivkan-lazy-spectre.console-dev
Jan 24, 2026
Merged

Lazy initialize Spectre.Console in XPlat command registration#7063
zivkan merged 1 commit intodevfrom
dev-zivkan-lazy-spectre.console-dev

Conversation

@zivkan
Copy link
Member

@zivkan zivkan commented Jan 19, 2026

Bug

Fixes: dotnet/sdk#52278

Description

This code has already been merged into the dotnet VMR, but NuGet.Client doesn't have a backflow configured for the 10.0.2xx branch: dotnet/dotnet#4139

Spectre.Console's AnsiConsole will send VT commands on initialzation, which breaks formatting of other parts of the dotnet CLI when it expects that the terminal has default settings. So, only initialize AnsiConsole when it's about to be used.

Tests were not added because testing this is very difficult. You can't test using a child process or redirecting to a file, because Spectre detects that the output is being redirected about avoids sending the VT commands. In order to test, we'd need to P/Invoke operating system specific APIs to open a new PTY. We'd then need all new child process test infrastructure to capture the output. If we just wanted to make sure that the VT command that Spectre sends on init isn't sent, we'd need to first figure out what VT command that is, but then searching for it in the output should be simple enough. However, if we wanted to validate that dotnet --info's output isn't being malformed, then we'd need to implement a lot of a terminal emulator to figure out what the console output would look like, and then validate there's no leading whitespace on the SDK version number list.

PR Checklist

@zivkan zivkan requested a review from a team as a code owner January 19, 2026 20:26
@zivkan zivkan requested review from martinrrm and nkolev92 January 19, 2026 20:26
@zivkan zivkan merged commit 4f7d030 into dev Jan 24, 2026
17 of 18 checks passed
@zivkan zivkan deleted the dev-zivkan-lazy-spectre.console-dev branch January 24, 2026 20:40
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.

[NETSDKE2E]With NET11 SDK installed, bad layout for "dotnet --info" when opening command with administrator

5 participants