-
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
Changes from all commits
7c2b3dc
95dd2dd
04be093
995f332
b7229a9
1085a15
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 |
---|---|---|
|
@@ -36,4 +36,10 @@ public static Dictionary<string, string> GetGlobalPropertiesFromArgs(string[] ar | |
} | ||
return globalProperties; | ||
} | ||
|
||
public static string GetPropertiesLaunchSettingsPath(string directoryPath, string propertiesDirectoryName) | ||
=> 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 commentThe reason will be displayed to describe this comment to others. Learn more. Is it expected to be able to put launch settings in 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. Yes, quoting from #48200:
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,13 +202,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; | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, simply |
||
} | ||
|
||
|
@@ -221,8 +217,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()); | ||
|
@@ -241,13 +236,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 = Path.GetDirectoryName(projectOrEntryPointFilePath)!; | ||
|
||
string propsDirectory; | ||
|
||
|
@@ -263,8 +254,37 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel | |
propsDirectory = "Properties"; | ||
} | ||
|
||
var launchSettingsPath = Path.Combine(buildPathContainer, propsDirectory, "launchSettings.json"); | ||
return launchSettingsPath; | ||
string launchSettingsPath = CommonRunHelpers.GetPropertiesLaunchSettingsPath(buildPathContainer, propsDirectory); | ||
bool hasLaunchSetttings = File.Exists(launchSettingsPath); | ||
|
||
string appName = Path.GetFileNameWithoutExtension(projectOrEntryPointFilePath); | ||
string runJsonPath = CommonRunHelpers.GetFlatLaunchSettingsPath(buildPathContainer, appName); | ||
bool hasRunJson = File.Exists(runJsonPath); | ||
|
||
if (hasLaunchSetttings) | ||
{ | ||
if (hasRunJson) | ||
{ | ||
Reporter.Output.WriteLine(string.Format(CliCommandStrings.RunCommandWarningRunJsonNotUsed, runJsonPath, launchSettingsPath).Yellow()); | ||
} | ||
|
||
return launchSettingsPath; | ||
} | ||
|
||
if (hasRunJson) | ||
{ | ||
return runJsonPath; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(launchProfile)) | ||
{ | ||
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile, launchProfile, $""" | ||
{launchSettingsPath} | ||
{runJsonPath} | ||
""").Bold().Red()); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
|
@@ -573,6 +593,7 @@ public static RunCommand FromParseResult(ParseResult parseResult) | |
out string? entryPointFilePath); | ||
|
||
bool noBuild = parseResult.HasOption(RunCommandParser.NoBuildOption); | ||
string launchProfile = parseResult.GetValue(RunCommandParser.LaunchProfileOption) ?? string.Empty; | ||
|
||
if (readCodeFromStdin && entryPointFilePath != null) | ||
{ | ||
|
@@ -583,6 +604,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). | ||
|
@@ -605,7 +631,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.
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.