-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[dotnet-cli] prompt for target framework using Spectre.Console
#51509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements the first part of the spec mentioned in: https://github.com/dotnet/sdk/blob/522c88a6abfc4a011556f839d15844d07ba62cd9/documentation/specs/dotnet-run-for-maui.md?plain=1#L35-L46 Add interactive target framework selection to `dotnet run` When running a multi-targeted project without specifying `--framework`, `dotnet run` now: * Prompts interactively (using `Spectre.Console`) to select a framework with arrow keys * Shows a formatted error list in non-interactive mode with available frameworks * Handles selection early before project build/evaluation * Removes redundant multi-TFM error checking from `ThrowUnableToRunError()` * Adds a few unit tests to validate these changes. This is currently WIP, as it introduces a "pre-built" `Spectre.Console` that I will need to setup in source-build in a PRs elsewhere.
So it doesn't require `mono`
There are other tests that do this
This test fails after I made it check TF at runtime. This was not even the existing behavior, I think we can remove this test.
|
/azp run sdk-unified-build |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds interactive target framework selection to the dotnet run command for multi-targeted projects. When a multi-targeted project is run without specifying a framework, the command now prompts the user to select one in interactive mode, or displays a helpful error message with available frameworks in non-interactive mode.
- Introduces
TargetFrameworkSelectorclass to handle framework selection logic - Adds Spectre.Console package for interactive prompting
- Updates error handling to show available frameworks and example commands
- Includes comprehensive integration tests for framework selection scenarios
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Run/GivenDotnetRunSelectsTargetFramework.cs | Adds comprehensive integration tests for target framework selection behavior |
| test/TestAssets/TestProjects/DotnetRunMultiTarget/Program.cs | Test project that outputs target framework information |
| test/TestAssets/TestProjects/DotnetRunMultiTarget/DotnetRunMultiTarget.csproj | Multi-targeted test project configuration |
| src/Cli/dotnet/dotnet.csproj | Adds Spectre.Console package reference |
| src/Cli/dotnet/Commands/xlf/*.xlf | Adds localization entries for new UI strings (state=new) |
| src/Cli/dotnet/Commands/Run/TargetFrameworkSelector.cs | New class implementing framework selection logic |
| src/Cli/dotnet/Commands/Run/RunCommand.cs | Integrates framework selection into run command execution flow |
| src/Cli/dotnet/Commands/CliCommandStrings.resx | Adds new localizable strings for framework selection UI |
| Directory.Packages.props | Adds Spectre.Console version 0.52.0 |
| using var collection = new ProjectCollection(globalProperties: globalProperties); | ||
| project = collection.LoadProject(projectFilePath); |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ProjectCollection is disposed immediately after loading the project, but the project variable is used outside the using block (line 49). This could lead to issues since the project is part of the collection that's being disposed. Consider moving the property value retrieval inside the using block or restructuring to avoid using the project after its collection is disposed.
Co-authored-by: Copilot <[email protected]>
|
/azp run sdk-unified-build |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Please also add Spectre.Console here: Lines 60 to 67 in 6a6992f
|
|
/azp run sdk-unified-build |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@premun @dkurepa do you know what might be going on here? Build |
|
@NikolaMilosavljevic same as here: dotnet/source-build-reference-packages#1447 (comment) You will have to pin darc for the time being (either in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks my boxes:
- supports long lists via scrolling
- is searchable
- has directions/feedback for users
- has good defaults for the common cases
I did a spot-check against the way the Aspire CLI uses prompts and this is right in line.
Implements the first part of the spec mentioned in:
sdk/documentation/specs/dotnet-run-for-maui.md
Lines 35 to 46 in 522c88a
Add interactive target framework selection to
dotnet runWhen running a multi-targeted project without specifying
--framework,dotnet runnow:Prompts interactively (using
Spectre.Console) to select a framework with arrow keysShows a formatted error list in non-interactive mode with available frameworks
Handles selection early before project build/evaluation
Removes redundant multi-TFM error checking from
ThrowUnableToRunError()Adds a few unit tests to validate these changes.
This is currently WIP, as it introduces a "pre-built"
Spectre.Consolethat I will need to setup in source-build in a PRs elsewhere.