Skip to content

Add support for flat launch settings #49769

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Jul 14, 2025

Resolves #48200.

@jjonescz jjonescz changed the title Sprint launch Add support for flat launch settings Jul 14, 2025
[InlineData(TestingConstants.Release)]
[Theory]
public void RunTestProjectWithTestsAndLaunchSettings_ShouldReturnExitCodeSuccess(string configuration)
[Theory, CombinatorialData]
Copy link
Member

Choose a reason for hiding this comment

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

Happy to see we have an updated test for dotnet test :)

FYI @nohwnd @mariam-abdulla @Evangelink

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Jul 14, 2025
@jjonescz jjonescz marked this pull request as ready for review July 15, 2025 06:45
@jjonescz jjonescz requested review from tmat and a team as code owners July 15, 2025 06:45
@jjonescz jjonescz requested review from a team and Copilot July 15, 2025 06:46
Copy link
Contributor

@Copilot 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 support for “flat” launch settings files (e.g. MyApp.run.json) alongside the existing launchSettings.json.
Key changes:

  • Updated CLI logic in RunCommand, CommonRunHelpers, and LaunchSettingsManager to locate and apply both legacy and flat launch settings.
  • Expanded tests in dotnet test, dotnet run, and dotnet-watch suites to cover flat launch settings; updated completion snapshots.
  • Updated resource strings and localization artifacts to reference both file patterns.

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Cli/dotnet/Commands/Run/CommonRunHelpers.cs Added helpers to build paths for both launch settings.
src/Cli/dotnet/Commands/Run/RunCommand.cs Updated launch settings lookup logic, error reporting.
src/Cli/dotnet/Commands/Run/LaunchSettings/LaunchSettingsManager.cs Changed TryApplyLaunchSettings to accept a file path.
src/Cli/dotnet/Commands/Test/SolutionAndProjectUtility.cs Kept test utility in sync with new lookup signature.
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs Extended test combinatorics for flat vs legacy profiles.
test/dotnet.Tests/CommandTests/Run/*.cs Added run.json-based launch profile tests.
test/dotnet-watch.Tests/Process/LaunchSettingsProfileTest.cs Adapted to use flat launch settings path.
test/dotnet.Tests/CompletionTests/snapshots/{zsh,pwsh}/DotnetCliSnapshotTests.VerifyCompletions.* Updated completion descriptions for --no-launch-profile.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.*.xlf and CliCommandStrings.resx Updated message strings to mention flat launch settings.
Comments suppressed due to low confidence (2)

test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsVbProj.cs:32

  • There is no testInstance variable defined in this test. It appears you meant to use the testProjectDirectory variable for the working directory. Please update the references accordingly so the test compiles.
                    {Path.Join(testInstance.Path, "My Project", "launchSettings.json")}

test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs:382

  • The variable testInstance is not defined here; the test uses testProjectDirectory earlier. Please replace testInstance.Path with the correct test directory variable so the test compiles and runs.
                    {Path.Join(testInstance.Path, "Properties", "launchSettings.json")}

@@ -36,4 +36,10 @@ public static Dictionary<string, string> GetGlobalPropertiesFromArgs(string[] ar
}
return globalProperties;
}

public static string GetPropertiesLaunchSettingsPath(string directoryPath, string propertiesDirectoryName)
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The file path helpers use both Path.Combine and Path.Join in this class. Consider unifying on one approach (e.g. Path.Combine) for consistency and clarity.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing helper used Path.Combine and I opted to preserve that to avoid a break.

Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile, launchProfile, $"""
{launchSettingsPath}
{runJsonPath}
""").Red());
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

[nitpick] Error messages elsewhere use .Bold().Red() for emphasis before writing to the reporter. For consistency, consider adding .Bold() here as well.

Suggested change
""").Red());
""").Bold().Red());

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a hard error (in fact, the command continues to run in spite of the error), so I feel like bolding it is not necessary.

<source>Do not attempt to use launchSettings.json to configure the application.</source>
<target state="translated">請勿嘗試使用 launchSettings.json 設定該應用程式。</target>
<note />
<source>Do not attempt to use launchSettings.json or [app].run.json to configure the application.</source>
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

Manual edits to .xlf localization files should be avoided. Please update the source strings in the .resx and regenerate all .xlf files via the MSBuild /t:UpdateXlf target to ensure consistency.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't modify those, the build did this.

@Youssef1313
Copy link
Member

@jjonescz Quick question, the new run.json is applicable to dotnet run file.cs only? Or applicable to both dotnet run file.cs and dotnet run --project MyProject.csproj?

@jjonescz
Copy link
Member Author

Quick question, the new run.json is applicable to dotnet run file.cs only? Or applicable to both dotnet run file.cs and dotnet run --project MyProject.csproj?

Both. Also dotnet test and dotnet watch.

@Youssef1313
Copy link
Member

Quick question, the new run.json is applicable to dotnet run file.cs only? Or applicable to both dotnet run file.cs and dotnet run --project MyProject.csproj?

Both. Also dotnet test and dotnet watch.

Yeah I was asking for the behavior of dotnet run for projects because that's what we want to match dotnet test with. Thanks for clarifying!

@tmat
Copy link
Member

tmat commented Jul 15, 2025

dotnet-watch changes LGTM

@jjonescz
Copy link
Member Author

@MiYanni @RikkiGibson @jaredpar for reviews, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-run-file Items related to the "dotnet run <file>" effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support launch profile configuration file named [ApplicationName].run.json in the app root
3 participants