Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 13, 2025

Refactors launch profile parsing and adds support for Executable command name.
Fixes environment variable expansion and adds tests.

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.

@copilot Good initial attempt, but we can clean this up some. Please address my review comments.

Copilot AI changed the title [WIP] Allow dotnet run to use launch profiles for Executable Add Executable launch profile support to dotnet run and dotnet watch Nov 13, 2025
Copilot AI requested a review from baronfel November 13, 2025 22:53
Copilot finished work on behalf of baronfel November 13, 2025 22:53
Copilot finished work on behalf of baronfel November 13, 2025 23:14
}

private static ProjectLaunchSettingsModel? TryGetLaunchProfileSettings(string projectDirectory, string projectNameWithoutExtension, string appDesignerFolder, BuildOptions buildOptions, string? profileName)
private static LaunchSettingsModel? TryGetLaunchProfileSettings(string projectDirectory, string projectNameWithoutExtension, string appDesignerFolder, BuildOptions buildOptions, string? profileName)
Copy link
Member

Choose a reason for hiding this comment

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

@dotnet/dotnet-testing if we expand the 'launch settings' handlers that are known, how should the testing experience react? does test support launch settings profiles today?

Copilot finished work on behalf of baronfel November 14, 2025 16:24
@Evangelink
Copy link
Member

@baronfel I just read in diagonal the PR. I think it'd be great to ensure that's also working for test verb.

cc @Youssef1313

Copilot AI and others added 7 commits November 19, 2025 08:37
- Created base LaunchSettingsModel with ProfileKind discriminator
- Derived ProjectLaunchSettingsModel and ExecutableLaunchSettingsModel
- Added JSON binding models for deserialization
- Updated providers to use JsonSerializer.Deserialize instead of manual traversal
- Exposed SupportedProfileTypes from LaunchSettingsManager
- Updated LaunchSettingsProfile.cs to use array of supported types with comment
- Updated RunCommand to use pattern matching on ProfileKind
- Split Execute method into ExecuteWithProjectProfile and ExecuteWithExecutableProfile
- Updated all method signatures to use base LaunchSettingsModel type

Co-authored-by: baronfel <[email protected]>
Changed hardcoded error message to use CliCommandStrings.LaunchProfileHandlerCannotBeLocated for proper localization support.

Co-authored-by: baronfel <[email protected]>
Simplified argument building logic to make it clearer that ApplicationArgs are properly escaped before being combined with launchSettings.CommandLineArgs. Added comments explaining that CommandLineArgs from JSON cannot be reliably parsed into tokens.

Co-authored-by: baronfel <[email protected]>
Extracted the common code from ExecuteWithProjectProfile and ExecuteWithExecutableProfile into a new ExecuteCommand method. This method handles:
- Applying launch settings to the command
- Applying environment variables from command line
- Sending telemetry
- Setting up Ctrl-C handler
- Executing the command

This reduces code duplication and makes the execution flow clearer.

Co-authored-by: baronfel <[email protected]>
Added tests to verify that the executable command handler correctly applies:
- Environment variables from launch profile
- Working directory settings
- Command line arguments combination (profile + command line)
- Environment variable expansion in executable paths

Created new test assets:
- AppForExecutableProfile: Helper app to verify environment and arguments
- AppWithDetailedExecutableProfile: Test project with various executable profiles

All tests verify the correct application of launch profile settings to the generated command.

Co-authored-by: baronfel <[email protected]>
@tmat tmat force-pushed the copilot/allow-dotnet-run-executable-support branch from 33d9898 to 1c8a35c Compare November 19, 2025 16:38
@tmat tmat requested a review from a team as a code owner November 19, 2025 16:38
@tmat tmat force-pushed the copilot/allow-dotnet-run-executable-support branch from 1c8a35c to 8cfe2ea Compare November 19, 2025 16:53
@tmat
Copy link
Member

tmat commented Nov 19, 2025

@Evangelink @Youssef1313

What should dotnet test do if the profile is Executable?

For example, if I specify:

{
    "profiles": {
        "Execute": {
            "commandName": "Executable",
            "executablePath": "dotnet",
            "commandLineArgs": "--version"
        }
    }
}

Should it just run dotnet --version? Doesn't seem very useful.

@Evangelink
Copy link
Member

@Evangelink @Youssef1313

What should dotnet test do if the profile is Executable?

For example, if I specify:

{
    "profiles": {
        "Execute": {
            "commandName": "Executable",
            "executablePath": "dotnet",
            "commandLineArgs": "--version"
        }
    }
}

Should it just run dotnet --version? Doesn't seem very useful.

I think the same question applies for dotnet run or dotnet watch. For me, dotnet test is equivalent to dotnet run sln (I know it's not supported, it's just to give a high level parallel for features support).

Now, this being said, I agree that if you do "conflicting" queries that can lead to be situations and I don't know what should be the proper UX here. I still tend to think I'd prefer to have something (good or bad) similar to dotnet run as much as possible.

@tmat
Copy link
Member

tmat commented Nov 20, 2025

The difference is that dotnet test passes various test related command line args when launching project. Should those be ignored?

See https://github.com/dotnet/sdk/blob/main/src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs#L88

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

Labels

Area-Run Issues relating to `dotnet run` Document for new feature Partner request requests from partners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants