-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -200,13 +200,9 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel | |||||
return true; | ||||||
} | ||||||
|
||||||
var launchSettingsPath = ReadCodeFromStdin ? null : TryFindLaunchSettings(ProjectFileFullPath ?? EntryPointFileFullPath!); | ||||||
if (!File.Exists(launchSettingsPath)) | ||||||
var launchSettingsPath = ReadCodeFromStdin ? null : TryFindLaunchSettings(projectOrEntryPointFilePath: ProjectFileFullPath ?? EntryPointFileFullPath!, launchProfile: LaunchProfile); | ||||||
if (launchSettingsPath is null) | ||||||
{ | ||||||
if (!string.IsNullOrEmpty(LaunchProfile)) | ||||||
{ | ||||||
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile, launchSettingsPath).Bold().Red()); | ||||||
} | ||||||
return true; | ||||||
} | ||||||
|
||||||
|
@@ -219,8 +215,7 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel | |||||
|
||||||
try | ||||||
{ | ||||||
var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); | ||||||
var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, LaunchProfile); | ||||||
var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsPath, LaunchProfile); | ||||||
if (!applyResult.Success) | ||||||
{ | ||||||
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); | ||||||
|
@@ -239,13 +234,9 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel | |||||
|
||||||
return true; | ||||||
|
||||||
static string? TryFindLaunchSettings(string projectOrEntryPointFilePath) | ||||||
static string? TryFindLaunchSettings(string projectOrEntryPointFilePath, string? launchProfile) | ||||||
{ | ||||||
var buildPathContainer = File.Exists(projectOrEntryPointFilePath) ? Path.GetDirectoryName(projectOrEntryPointFilePath) : projectOrEntryPointFilePath; | ||||||
if (buildPathContainer is null) | ||||||
{ | ||||||
return null; | ||||||
} | ||||||
var buildPathContainer = File.Exists(projectOrEntryPointFilePath) ? Path.GetDirectoryName(projectOrEntryPointFilePath)! : projectOrEntryPointFilePath; | ||||||
|
||||||
string propsDirectory; | ||||||
|
||||||
|
@@ -261,8 +252,28 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel | |||||
propsDirectory = "Properties"; | ||||||
} | ||||||
|
||||||
var launchSettingsPath = Path.Combine(buildPathContainer, propsDirectory, "launchSettings.json"); | ||||||
return launchSettingsPath; | ||||||
var launchSettingsPath = CommonRunHelpers.GetPropertiesLaunchSettingsPath(buildPathContainer, propsDirectory); | ||||||
if (File.Exists(launchSettingsPath)) | ||||||
{ | ||||||
return launchSettingsPath; | ||||||
} | ||||||
|
||||||
string appName = Path.GetFileNameWithoutExtension(projectOrEntryPointFilePath); | ||||||
string runJsonPath = CommonRunHelpers.GetFlatLaunchSettingsPath(buildPathContainer, appName); | ||||||
if (File.Exists(runJsonPath)) | ||||||
{ | ||||||
return runJsonPath; | ||||||
} | ||||||
|
||||||
if (!string.IsNullOrEmpty(launchProfile)) | ||||||
{ | ||||||
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile, launchProfile, $""" | ||||||
{launchSettingsPath} | ||||||
{runJsonPath} | ||||||
""").Red()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Error messages elsewhere use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
} | ||||||
|
||||||
return null; | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -552,6 +563,7 @@ public static RunCommand FromParseResult(ParseResult parseResult) | |||||
string? projectFilePath = DiscoverProjectFilePath(projectOption, readCodeFromStdin, ref args, out string? entryPointFilePath); | ||||||
|
||||||
bool noBuild = parseResult.HasOption(RunCommandParser.NoBuildOption); | ||||||
string launchProfile = parseResult.GetValue(RunCommandParser.LaunchProfileOption) ?? string.Empty; | ||||||
|
||||||
if (readCodeFromStdin && entryPointFilePath != null) | ||||||
{ | ||||||
|
@@ -562,6 +574,11 @@ public static RunCommand FromParseResult(ParseResult parseResult) | |||||
throw new GracefulException(CliCommandStrings.InvalidOptionForStdin, RunCommandParser.NoBuildOption.Name); | ||||||
} | ||||||
|
||||||
if (!string.IsNullOrWhiteSpace(launchProfile)) | ||||||
{ | ||||||
throw new GracefulException(CliCommandStrings.InvalidOptionForStdin, RunCommandParser.LaunchProfileOption.Name); | ||||||
} | ||||||
|
||||||
// If '-' is specified as the input file, read all text from stdin into a temporary file and use that as the entry point. | ||||||
// We create a new directory for each file so other files are not included in the compilation. | ||||||
// We fail if the file already exists to avoid reusing the same file for multiple stdin runs (in case the random name is duplicate). | ||||||
|
@@ -584,7 +601,7 @@ public static RunCommand FromParseResult(ParseResult parseResult) | |||||
noBuild: noBuild, | ||||||
projectFileFullPath: projectFilePath, | ||||||
entryPointFileFullPath: entryPointFilePath, | ||||||
launchProfile: parseResult.GetValue(RunCommandParser.LaunchProfileOption) ?? string.Empty, | ||||||
launchProfile: launchProfile, | ||||||
noLaunchProfile: parseResult.HasOption(RunCommandParser.NoLaunchProfileOption), | ||||||
noLaunchProfileArguments: parseResult.HasOption(RunCommandParser.NoLaunchProfileArgumentsOption), | ||||||
noRestore: parseResult.HasOption(RunCommandParser.NoRestoreOption) || parseResult.HasOption(RunCommandParser.NoBuildOption), | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
andPath.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.