Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Implements the first part of the spec mentioned in:

* "Pre-run evaluation"
* If the project is multi-targeted, containing the
`$(TargetFrameworks)` property _and_ that property has more than
one item in it, and `-f` was not supplied...
* Prompt the user to select from a list of the
`$(TargetFrameworks)`
* Non-interactive mode will give a friendly error message,
suggesting to supply the `-f` property, listing available target
frameworks in the project.

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.

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.
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.
@jonathanpeppers
Copy link
Member Author

/azp run sdk-unified-build

@azure-pipelines
Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

Copy link
Contributor

Copilot AI left a 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 TargetFrameworkSelector class 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

Comment on lines +40 to +41
using var collection = new ProjectCollection(globalProperties: globalProperties);
project = collection.LoadProject(projectFilePath);
Copy link

Copilot AI Oct 31, 2025

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.

Copilot uses AI. Check for mistakes.
@NikolaMilosavljevic
Copy link
Member

/azp run sdk-unified-build

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@akoeplinger
Copy link
Member

Please also add Spectre.Console here:

sdk/eng/Signing.props

Lines 60 to 67 in 6a6992f

ReSign 3rd party files that we use in the product
-->
<ItemGroup>
<FileSignInfo Include="MessagePack.Annotations.dll" CertificateName="$(ExternalCertificateId)" />
<FileSignInfo Include="MessagePack.dll" CertificateName="$(ExternalCertificateId)" />
<FileSignInfo Include="Nerdbank.Streams.dll" CertificateName="$(ExternalCertificateId)" />
<FileSignInfo Include="Newtonsoft.Json.dll" CertificateName="$(ExternalCertificateId)" />
<FileSignInfo Include="Valleysoft.DockerCredsProvider.dll" CertificateName="$(ExternalCertificateId)" />

@jonathanpeppers
Copy link
Member Author

/azp run sdk-unified-build

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@NikolaMilosavljevic
Copy link
Member

sdk-unified-build pipeline is failing to synchronize the VMR. I've never seen this error before:

info: Rebasing darc/forward/00f07cf-be28ec7 onto HEAD...
dbug: Executing command: 'git -C /__w/1/vmr checkout HEAD'
dbug: Executing command: 'git -C /__w/1/vmr merge --squash darc/forward/00f07cf-be28ec7'
dbug: Executing command: 'git -C /__w/1/vmr branch -D darc/forward/00f07cf-be28ec7'
dbug: Executing command: 'git -C /__w/1/vmr show HEAD:src/source-manifest.json'
dbug: Executing command: 'git -C /__w/1/vmr add /__w/1/vmr/src/source-manifest.json'
fail: Failed to synchronize repo to VMR
      Failed to delete branch darc/forward/00f07cf-be28ec7 in /__w/1/vmr
      Exit code: 1
      Std err:
      error: cannot delete branch 'darc/forward/00f07cf-be28ec7' used by worktree at '/__w/1/vmr'

@premun @dkurepa do you know what might be going on here? Build

@baronfel baronfel added Area-Run Issues relating to `dotnet run` Area-CLI and removed Area-Infrastructure labels Nov 3, 2025
@premun
Copy link
Member

premun commented Nov 3, 2025

@NikolaMilosavljevic same as here: dotnet/source-build-reference-packages#1447 (comment)

You will have to pin darc for the time being (either in dotnet-tools.json or like this)

Copy link
Member

@baronfel baronfel left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-CLI Area-Run Issues relating to `dotnet run`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants