Skip to content

Commit fc944af

Browse files
authored
Implements --no-launch-profile-arguments dotnet-run option (#45841)
1 parent 6319104 commit fc944af

18 files changed

+117
-17
lines changed

src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
<data name="CommandOptionNoLaunchProfileDescription" xml:space="preserve">
140140
<value>Do not attempt to use launchSettings.json to configure the application.</value>
141141
</data>
142+
<data name="CommandOptionNoLaunchProfileArgumentsDescription" xml:space="preserve">
143+
<value>Do not use arguments specified in launch profile to run the application.</value>
144+
</data>
142145
<data name="ConfigurationOptionDescription" xml:space="preserve">
143146
<value>The configuration to run for. The default for most projects is 'Debug'.</value>
144147
</data>

src/Cli/dotnet/commands/dotnet-run/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static RunCommand FromParseResult(ParseResult parseResult)
5959
projectFileOrDirectory: parseResult.GetValue(RunCommandParser.ProjectOption),
6060
launchProfile: parseResult.GetValue(RunCommandParser.LaunchProfileOption),
6161
noLaunchProfile: parseResult.HasOption(RunCommandParser.NoLaunchProfileOption),
62+
noLaunchProfileArguments: parseResult.HasOption(RunCommandParser.NoLaunchProfileArgumentsOption),
6263
noRestore: parseResult.HasOption(RunCommandParser.NoRestoreOption) || parseResult.HasOption(RunCommandParser.NoBuildOption),
6364
interactive: parseResult.HasOption(RunCommandParser.InteractiveOption),
6465
verbosity: parseResult.HasOption(CommonOptions.VerbosityOption) ? parseResult.GetValue(CommonOptions.VerbosityOption) : null,

src/Cli/dotnet/commands/dotnet-run/RunCommand.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,36 @@ public partial class RunCommand
2020
{
2121
private record RunProperties(string? RunCommand, string? RunArguments, string? RunWorkingDirectory);
2222

23-
public bool NoBuild { get; private set; }
24-
public string ProjectFileFullPath { get; private set; }
23+
public bool NoBuild { get; }
24+
public string? ProjectFileOrDirectory { get; }
25+
public string ProjectFileFullPath { get; }
2526
public string[] Args { get; set; }
26-
public bool NoRestore { get; private set; }
27+
public bool NoRestore { get; }
2728
public VerbosityOptions? Verbosity { get; }
28-
public bool Interactive { get; private set; }
29-
public string[] RestoreArgs { get; private set; }
29+
public bool Interactive { get; }
30+
public string[] RestoreArgs { get; }
3031

3132
/// <summary>
3233
/// Environment variables specified on command line via -e option.
3334
/// </summary>
34-
public IReadOnlyDictionary<string, string> EnvironmentVariables { get; private set; }
35+
public IReadOnlyDictionary<string, string> EnvironmentVariables { get; }
3536

3637
private bool ShouldBuild => !NoBuild;
3738

38-
public string LaunchProfile { get; private set; }
39-
public bool NoLaunchProfile { get; private set; }
40-
private bool UseLaunchProfile => !NoLaunchProfile;
39+
public string LaunchProfile { get; }
40+
public bool NoLaunchProfile { get; }
41+
42+
/// <summary>
43+
/// True to ignore command line arguments specified by launch profile.
44+
/// </summary>
45+
public bool NoLaunchProfileArguments { get; }
4146

4247
public RunCommand(
4348
bool noBuild,
4449
string? projectFileOrDirectory,
4550
string launchProfile,
4651
bool noLaunchProfile,
52+
bool noLaunchProfileArguments,
4753
bool noRestore,
4854
bool interactive,
4955
VerbosityOptions? verbosity,
@@ -52,9 +58,11 @@ public RunCommand(
5258
IReadOnlyDictionary<string, string> environmentVariables)
5359
{
5460
NoBuild = noBuild;
61+
ProjectFileOrDirectory = projectFileOrDirectory;
5562
ProjectFileFullPath = DiscoverProjectFilePath(projectFileOrDirectory);
5663
LaunchProfile = launchProfile;
5764
NoLaunchProfile = noLaunchProfile;
65+
NoLaunchProfileArguments = noLaunchProfileArguments;
5866
Args = args;
5967
Interactive = interactive;
6068
NoRestore = noRestore;
@@ -125,7 +133,7 @@ private void ApplyLaunchSettingsProfileToCommand(ICommand targetCommand, Project
125133
targetCommand.EnvironmentVariable(entry.Key, value);
126134
}
127135

128-
if (string.IsNullOrEmpty(targetCommand.CommandArgs) && launchSettings.CommandLineArgs != null)
136+
if (!NoLaunchProfileArguments && string.IsNullOrEmpty(targetCommand.CommandArgs) && launchSettings.CommandLineArgs != null)
129137
{
130138
targetCommand.SetCommandArgs(launchSettings.CommandLineArgs);
131139
}
@@ -134,7 +142,7 @@ private void ApplyLaunchSettingsProfileToCommand(ICommand targetCommand, Project
134142
private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel? launchSettingsModel)
135143
{
136144
launchSettingsModel = default;
137-
if (!UseLaunchProfile)
145+
if (NoLaunchProfile)
138146
{
139147
return true;
140148
}

src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ internal static class RunCommandParser
3434
Description = LocalizableStrings.CommandOptionNoLaunchProfileDescription
3535
};
3636

37+
public static readonly CliOption<bool> NoLaunchProfileArgumentsOption = new("--no-launch-profile-arguments")
38+
{
39+
Description = LocalizableStrings.CommandOptionNoLaunchProfileArgumentsDescription
40+
};
41+
3742
public static readonly CliOption<bool> NoBuildOption = new("--no-build")
3843
{
3944
Description = LocalizableStrings.CommandOptionNoBuildDescription

src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)