diff --git a/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx index ca6c5bee84ad..7835c0542477 100644 --- a/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx @@ -139,6 +139,9 @@ Do not attempt to use launchSettings.json to configure the application. + + Do not use arguments specified in launch profile to run the application. + The configuration to run for. The default for most projects is 'Debug'. diff --git a/src/Cli/dotnet/commands/dotnet-run/Program.cs b/src/Cli/dotnet/commands/dotnet-run/Program.cs index 1303fee09e2a..1dee09851a17 100644 --- a/src/Cli/dotnet/commands/dotnet-run/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-run/Program.cs @@ -59,6 +59,7 @@ public static RunCommand FromParseResult(ParseResult parseResult) projectFileOrDirectory: parseResult.GetValue(RunCommandParser.ProjectOption), launchProfile: parseResult.GetValue(RunCommandParser.LaunchProfileOption), noLaunchProfile: parseResult.HasOption(RunCommandParser.NoLaunchProfileOption), + noLaunchProfileArguments: parseResult.HasOption(RunCommandParser.NoLaunchProfileArgumentsOption), noRestore: parseResult.HasOption(RunCommandParser.NoRestoreOption) || parseResult.HasOption(RunCommandParser.NoBuildOption), interactive: parseResult.HasOption(RunCommandParser.InteractiveOption), verbosity: parseResult.HasOption(CommonOptions.VerbosityOption) ? parseResult.GetValue(CommonOptions.VerbosityOption) : null, diff --git a/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs b/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs index bda6db65988c..0f084c9c4d0a 100644 --- a/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs @@ -20,30 +20,36 @@ public partial class RunCommand { private record RunProperties(string? RunCommand, string? RunArguments, string? RunWorkingDirectory); - public bool NoBuild { get; private set; } - public string ProjectFileFullPath { get; private set; } + public bool NoBuild { get; } + public string? ProjectFileOrDirectory { get; } + public string ProjectFileFullPath { get; } public string[] Args { get; set; } - public bool NoRestore { get; private set; } + public bool NoRestore { get; } public VerbosityOptions? Verbosity { get; } - public bool Interactive { get; private set; } - public string[] RestoreArgs { get; private set; } + public bool Interactive { get; } + public string[] RestoreArgs { get; } /// /// Environment variables specified on command line via -e option. /// - public IReadOnlyDictionary EnvironmentVariables { get; private set; } + public IReadOnlyDictionary EnvironmentVariables { get; } private bool ShouldBuild => !NoBuild; - public string LaunchProfile { get; private set; } - public bool NoLaunchProfile { get; private set; } - private bool UseLaunchProfile => !NoLaunchProfile; + public string LaunchProfile { get; } + public bool NoLaunchProfile { get; } + + /// + /// True to ignore command line arguments specified by launch profile. + /// + public bool NoLaunchProfileArguments { get; } public RunCommand( bool noBuild, string? projectFileOrDirectory, string launchProfile, bool noLaunchProfile, + bool noLaunchProfileArguments, bool noRestore, bool interactive, VerbosityOptions? verbosity, @@ -52,9 +58,11 @@ public RunCommand( IReadOnlyDictionary environmentVariables) { NoBuild = noBuild; + ProjectFileOrDirectory = projectFileOrDirectory; ProjectFileFullPath = DiscoverProjectFilePath(projectFileOrDirectory); LaunchProfile = launchProfile; NoLaunchProfile = noLaunchProfile; + NoLaunchProfileArguments = noLaunchProfileArguments; Args = args; Interactive = interactive; NoRestore = noRestore; @@ -125,7 +133,7 @@ private void ApplyLaunchSettingsProfileToCommand(ICommand targetCommand, Project targetCommand.EnvironmentVariable(entry.Key, value); } - if (string.IsNullOrEmpty(targetCommand.CommandArgs) && launchSettings.CommandLineArgs != null) + if (!NoLaunchProfileArguments && string.IsNullOrEmpty(targetCommand.CommandArgs) && launchSettings.CommandLineArgs != null) { targetCommand.SetCommandArgs(launchSettings.CommandLineArgs); } @@ -134,7 +142,7 @@ private void ApplyLaunchSettingsProfileToCommand(ICommand targetCommand, Project private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel? launchSettingsModel) { launchSettingsModel = default; - if (!UseLaunchProfile) + if (NoLaunchProfile) { return true; } diff --git a/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs index 2ced3abe2636..22a6e3784be3 100644 --- a/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -34,6 +34,11 @@ internal static class RunCommandParser Description = LocalizableStrings.CommandOptionNoLaunchProfileDescription }; + public static readonly CliOption NoLaunchProfileArgumentsOption = new("--no-launch-profile-arguments") + { + Description = LocalizableStrings.CommandOptionNoLaunchProfileArgumentsDescription + }; + public static readonly CliOption NoBuildOption = new("--no-build") { Description = LocalizableStrings.CommandOptionNoBuildDescription diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf index ad803e3945c6..b107331470c2 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf @@ -17,6 +17,11 @@ K sestavení a spuštění aplikace se použije určená platforma. Tato platforma musí být zadaná v souboru projektu. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Cesta ke spouštěnému souboru projektu (výchozí je aktuální adresář, pokud existuje jenom jeden projekt) diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf index 44a232687444..898be7f9ff87 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf @@ -17,6 +17,11 @@ Erstellt die App mit dem angegebenen Framework und führt sie aus. Das Framework muss in der Projektdatei angegeben werden. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Der Pfad zur auszuführenden Projektdatei (standardmäßig das aktuelle Verzeichnis, falls nur ein einzelnes Projekt vorhanden ist). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf index 7f8d692f3ddd..f274ca5e3ae4 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf @@ -17,6 +17,11 @@ Compila y ejecuta la aplicación con la plataforma especificada. La plataforma se debe especificar en el archivo de proyecto. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Ruta de acceso al archivo del proyecto que debe ejecutarse (si solo hay un proyecto, es el directorio actual de forma predeterminada). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf index 765e8c7a91eb..6e6eb604dde2 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf @@ -17,6 +17,11 @@ Générez et exécutez l'application à l'aide du framework spécifié. Le framework doit être spécifié dans le fichier projet. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Chemin du fichier projet à exécuter (la valeur par défaut est le répertoire actif s'il n'y a qu'un seul projet). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf index 64c2db2f1e9c..4195434f7abb 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf @@ -17,6 +17,11 @@ Consente di compilare ed eseguire l'app con il framework specificato. Il framework deve essere specificato nel file di progetto. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Percorso del file di progetto da eseguire. Se è presente un solo progetto, per impostazione predefinita viene usata la directory corrente. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf index c1e3dc0c821d..517856cff983 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf @@ -17,6 +17,11 @@ 指定されたフレームワークを使用して、アプリを構築して実行します。フレームワークはプロジェクト ファイルで指定する必要があります。 + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). 実行するプロジェクト ファイルへのパス (プロジェクトが 1 つのみの場合、既定は現在のディレクトリです)。 diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf index fedd253c635a..268d33314952 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf @@ -17,6 +17,11 @@ 지정된 프레임워크를 사용하여 앱을 빌드 및 실행합니다. 프로젝트 파일에서 프레임워크를 지정해야 합니다. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). 실행할 프로젝트 파일의 경로입니다(프로젝트가 하나만 있는 경우 현재 디렉터리로 기본 설정됨). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf index 36aba105fc80..a73a54114dd3 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf @@ -17,6 +17,11 @@ Skompiluj i uruchom aplikację przy użyciu określonej platformy. Platforma musi być określona w pliku projektu. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Ścieżka do pliku projektu, który ma zostać uruchomiony (w przypadku tylko jednego projektu wartością domyślną jest bieżący katalog). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf index 334e435c446c..953c3b715658 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf @@ -17,6 +17,11 @@ Compila e executa um aplicativo usando a estrutura especificada. A estrutura deve ser especificada no arquivo de projeto. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). O caminho para o arquivo de projeto a ser executado (usará como padrão o diretório atual se houver apenas um projeto). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf index 4d27d2d19ecc..d648877af6f7 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf @@ -17,6 +17,11 @@ Сборка и выполнение приложения с использованием определенной платформы. Платформа должна быть указана в файле проекта. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Путь к выполняемому файлу проекта (по умолчанию — текущий каталог, если имеется только один проект). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf index 3a96699af96c..70aabe591405 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf @@ -17,6 +17,11 @@ Uygulamayı belirtilen çerçeveyi kullanarak derleyin ve çalıştırın. Çerçevenin proje dosyasında belirtilmesi gerekir. + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). Çalıştırılacak proje dosyasının yolu (yalnızca bir proje varsa, geçerli dizin varsayılan olarak kullanılır). diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf index 995d5b6ab239..2e9ecdafef26 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf @@ -17,6 +17,11 @@ 使用指定的框架生成和运行应用。框架必须在项目文件中指定。 + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). 要运行的项目文件的路径(如果只有一个项目,则默认使用当前目录)。 diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf index a2aa993f7344..86688e07f43b 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf @@ -17,6 +17,11 @@ 使用指定的架構建置及執行應用程式。架構必須在專案檔中指定。 + + Do not use arguments specified in launch profile to run the application. + Do not use arguments specified in launch profile to run the application. + + The path to the project file to run (defaults to the current directory if there is only one project). 要執行之專案檔的路徑 (如果只有一個專案,預設為目前的目錄)。 diff --git a/test/dotnet-run.Tests/GivenDotnetRunBuildsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunBuildsCsProj.cs index 8b0d11e0b98f..87604b60d47c 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunBuildsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunBuildsCsProj.cs @@ -856,21 +856,39 @@ public void EnvVariablesSpecifiedInLaunchProfileOverrideImplicitlySetVariables() [Fact] public void ItIncludesCommandArgumentsSpecifiedInLaunchSettings() { - var expectedValue = "TestAppCommandLineArguments"; - var secondExpectedValue = "SecondTestAppCommandLineArguments"; - var testAppName = "TestAppWithLaunchSettings"; - var testInstance = _testAssetsManager.CopyTestAsset(testAppName) + var testInstance = _testAssetsManager.CopyTestAsset("TestAppWithLaunchSettings") .WithSource(); + // launchSettings.json specifies commandLineArgs="TestAppCommandLineArguments SecondTestAppCommandLineArguments" + new DotnetCommand(Log, "run") .WithWorkingDirectory(testInstance.Path) .Execute() .Should() .Pass() .And - .HaveStdOutContaining(expectedValue) + .HaveStdOutContaining("TestAppCommandLineArguments") + .And + .HaveStdOutContaining("SecondTestAppCommandLineArguments"); + } + + [Fact] + public void ItIgnoresCommandArgumentsSpecifiedInLaunchSettings() + { + var testInstance = _testAssetsManager.CopyTestAsset("TestAppWithLaunchSettings") + .WithSource(); + + // launchSettings.json specifies commandLineArgs="TestAppCommandLineArguments SecondTestAppCommandLineArguments" + + new DotnetCommand(Log, "run", "--no-launch-profile-arguments") + .WithWorkingDirectory(testInstance.Path) + .Execute() + .Should() + .Pass() + .And + .NotHaveStdOutContaining("TestAppCommandLineArguments") .And - .HaveStdOutContaining(secondExpectedValue); + .NotHaveStdOutContaining("SecondTestAppCommandLineArguments"); } [Fact]