-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
[InlineData(TestingConstants.Release)] | ||
[Theory] | ||
public void RunTestProjectWithTestsAndLaunchSettings_ShouldReturnExitCodeSuccess(string configuration) | ||
[Theory, CombinatorialData] |
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.
Happy to see we have an updated test for dotnet test
:)
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 support for “flat” launch settings files (e.g. MyApp.run.json
) alongside the existing launchSettings.json
.
Key changes:
- Updated CLI logic in
RunCommand
,CommonRunHelpers
, andLaunchSettingsManager
to locate and apply both legacy and flat launch settings. - Expanded tests in
dotnet test
,dotnet run
, anddotnet-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 thetestProjectDirectory
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 usestestProjectDirectory
earlier. Please replacetestInstance.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) |
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.
[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.
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 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()); |
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.
[nitpick] Error messages elsewhere use .Bold().Red()
for emphasis before writing to the reporter. For consistency, consider adding .Bold()
here as well.
""").Red()); | |
""").Bold().Red()); |
Copilot uses AI. Check for mistakes.
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 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.
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 location you moved this from did bold it though.
<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> |
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.
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.
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.
I didn't modify those, the build did this.
@jjonescz Quick question, the new |
Both. Also |
Yeah I was asking for the behavior of |
dotnet-watch changes LGTM |
@MiYanni @RikkiGibson @jaredpar for reviews, thanks |
@RikkiGibson @jaredpar for reviews, thanks |
@RikkiGibson @333fred for reviews, thanks |
=> Path.Combine(directoryPath, propertiesDirectoryName, "launchSettings.json"); | ||
|
||
public static string GetFlatLaunchSettingsPath(string directoryPath, string projectNameWithoutExtension) | ||
=> Path.Join(directoryPath, $"{projectNameWithoutExtension}.run.json"); |
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.
Is it expected to be able to put launch settings in MyProject/MyProject.run.json
alongside MyProject/MyProject.csproj
?
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.
Yes, quoting from #48200:
It also allows project-based apps to simplify their file structure by not needing to have a Properties directory to put the launchSettings.json file in.
if (!string.IsNullOrEmpty(LaunchProfile)) | ||
{ | ||
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile, launchSettingsPath).Bold().Red()); | ||
} | ||
return true; |
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.
what does the return value of this method mean? "Either we don't need launch settings, or we do, and we found it?"
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.
Yes, simply false
means there was an error and we should not continue (and the return code from the CLI should be non-zero); true
means success and we can continue (and the return code from the CLI should be zero).
{ | ||
return null; | ||
} | ||
var buildPathContainer = File.Exists(projectOrEntryPointFilePath) ? Path.GetDirectoryName(projectOrEntryPointFilePath)! : projectOrEntryPointFilePath; |
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.
I am struggling a bit to follow this File.Exists check. I realize it is pre-existing code. But what is this doing? Is this really saying: if this is a file, then use its containing directory, otherwise assume it's a directory and use the path as-is? Is that something we should verify (e.g. buildPathContainer
should always be a directory on disk)?
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.
Hm, looks like the check is unnecessary, the projectOrEntryPointFilePath
should always be a path, we should never get a directory there (we check that when parsing the command). I will remove it.
"""); | ||
Directory.CreateDirectory(Path.Join(testInstance.Path, "Properties")); | ||
File.WriteAllText(Path.Join(testInstance.Path, "Properties", "launchSettings.json"), s_launchSettings.Replace("TestProfileMessage", "PropertiesLaunchSettingsJson")); | ||
File.WriteAllText(Path.Join(testInstance.Path, "Program.run.json"), s_launchSettings.Replace("TestProfileMessage", "ProgramRunJson")); |
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.
I am curious if this is a situation that the CLI should warn about. However, it doesn't seem super important.
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.
Sounds good to me, I will add a warning, thanks.
Resolves #48200.