From c4f2c66f7a60f121bd9c6ad2dd82c442c19828be Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Tue, 13 Jul 2021 10:18:16 -0700 Subject: [PATCH 1/5] Adding OS and arch command line options --- src/Cli/dotnet/CommonLocalizableStrings.resx | 11 ++++- src/Cli/dotnet/CommonOptions.cs | 49 ++++++++++++++++++- .../dotnet-build/BuildCommandParser.cs | 2 + .../dotnet-publish/PublishCommandParser.cs | 2 + .../commands/dotnet-run/RunCommandParser.cs | 2 + .../commands/dotnet-test/TestCommandParser.cs | 2 + .../install/ToolInstallCommandParser.cs | 2 + .../xlf/CommonLocalizableStrings.cs.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.de.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.es.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.fr.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.it.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.ja.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.ko.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.pl.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.pt-BR.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.ru.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.tr.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.zh-Hans.xlf | 15 ++++++ .../xlf/CommonLocalizableStrings.zh-Hant.xlf | 15 ++++++ .../GivenDotnetBuildInvocation.cs | 30 ++++++++++++ 21 files changed, 293 insertions(+), 2 deletions(-) diff --git a/src/Cli/dotnet/CommonLocalizableStrings.resx b/src/Cli/dotnet/CommonLocalizableStrings.resx index 4b87b84ac643..70501b30e84e 100644 --- a/src/Cli/dotnet/CommonLocalizableStrings.resx +++ b/src/Cli/dotnet/CommonLocalizableStrings.resx @@ -674,4 +674,13 @@ setx PATH "%PATH%;{0}" Allows prerelease packages to be installed. - \ No newline at end of file + + The target architecture. + + + The target operating system. + + + Resolving the current runtime identifier failed. + + diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index d3ec86e24bf6..54e906a503ad 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -6,6 +6,9 @@ using System.CommandLine; using System.IO; using Microsoft.DotNet.Tools.Common; +using System.Collections.Generic; +using System.Linq; +using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Cli { @@ -35,7 +38,7 @@ public static Option FrameworkOption(string description) => description) { ArgumentHelpName = CommonLocalizableStrings.FrameworkArgumentName - + }.ForwardAsSingle(o => $"-property:TargetFramework={o}") .AddSuggestions(Suggest.TargetFrameworksFromProjectFile()); @@ -91,6 +94,18 @@ public static Option InteractiveOption() => "--interactive", CommonLocalizableStrings.CommandInteractiveOptionDescription); + public static Option ArchitectureOption(bool includeShortVersion = true) => + new ForwardedOption( + includeShortVersion ? new string[] { "--arch", "-a" } : new string[] { "--arch" }, + CommonLocalizableStrings.ArchitectureOptionDescription) + .SetForwardingFunction(ResolveArchOptionToRuntimeIdentifier); + + public static Option OperatingSystemOption() => + new ForwardedOption( + "--os", + CommonLocalizableStrings.OperatingSystemOptionDescription) + .SetForwardingFunction(ResolveOsOptionToRuntimeIdentifier); + public static Option DebugOption() => new Option("--debug"); public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosity) @@ -100,6 +115,38 @@ public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosi verbosity.Equals(VerbosityOptions.d) || verbosity.Equals(VerbosityOptions.detailed); } + + internal static IEnumerable ResolveArchOptionToRuntimeIdentifier(string arg) + { + var currentRid = GetCurrentRuntimeId(); + var os = currentRid.Substring(0, currentRid.LastIndexOf("-")); + return new string[] { $"-property:RuntimeIdentifier={os}-{arg}", "-property:SelfContained=true" }; + } + + internal static IEnumerable ResolveOsOptionToRuntimeIdentifier(string arg) + { + var currentRid = GetCurrentRuntimeId(); + var arch = currentRid.Substring(currentRid.LastIndexOf("-") + 1, currentRid.Length - currentRid.LastIndexOf("-") - 1); + return new string[] { $"-property:RuntimeIdentifier={arg}-{arch}", "-property:SelfContained=true" }; + } + + private static string GetCurrentRuntimeId() + { + var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath); + dotnetRootPath = dotnetRootPath.Contains("dotnet") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); + var ridFileName = "NETCoreSdkRuntimeIdentifierChain.txt"; + string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) ? + Path.Combine(Directory.GetDirectories(Path.Combine(dotnetRootPath, "sdk"))[0], ridFileName) : + Path.Combine(dotnetRootPath, "sdk", Product.Version, ridFileName); + string[] currentRuntimeIdentifiers = File.Exists(runtimeIdentifierChainPath) ? + File.ReadAllLines(runtimeIdentifierChainPath).Where(l => !string.IsNullOrEmpty(l)).ToArray() : + new string[] { }; + if (currentRuntimeIdentifiers == null || !currentRuntimeIdentifiers.Any() || !currentRuntimeIdentifiers[0].Contains("-")) + { + throw new GracefulException(CommonLocalizableStrings.CannotResolveRuntimeIdentifier); + } + return currentRuntimeIdentifiers[0]; // First rid is the most specific (ex win-x64) + } } public enum VerbosityOptions diff --git a/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs index 668c03a99d6f..5a4adc5e6cf2 100644 --- a/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -49,6 +49,8 @@ public static Command GetCommand() command.AddOption(NoIncrementalOption); command.AddOption(NoDependenciesOption); command.AddOption(NoLogoOption); + command.AddOption(CommonOptions.ArchitectureOption()); + command.AddOption(CommonOptions.OperatingSystemOption()); return command; } diff --git a/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 6fb7479b5b87..6344de64f300 100644 --- a/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -61,6 +61,8 @@ public static Command GetCommand() command.AddOption(CommonOptions.InteractiveMsBuildForwardOption()); command.AddOption(NoRestoreOption); command.AddOption(CommonOptions.VerbosityOption()); + command.AddOption(CommonOptions.ArchitectureOption()); + command.AddOption(CommonOptions.OperatingSystemOption()); return command; } diff --git a/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs index 684b68d7821c..546db2830395 100644 --- a/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -47,6 +47,8 @@ public static Command GetCommand() command.AddOption(InteractiveOption); command.AddOption(NoRestoreOption); command.AddOption(CommonOptions.VerbosityOption()); + command.AddOption(CommonOptions.ArchitectureOption()); + command.AddOption(CommonOptions.OperatingSystemOption()); command.TreatUnmatchedTokensAsErrors = false; return command; diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index 3699aafac7d7..24751b2809f1 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -138,6 +138,8 @@ public static Command GetCommand() command.AddOption(NoRestoreOption); command.AddOption(CommonOptions.InteractiveMsBuildForwardOption()); command.AddOption(CommonOptions.VerbosityOption()); + command.AddOption(CommonOptions.ArchitectureOption(false)); + command.AddOption(CommonOptions.OperatingSystemOption()); return command; } diff --git a/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs b/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs index 8197a90ed0c2..3d5928f616d8 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs @@ -55,6 +55,8 @@ public static Command GetCommand() command.AddOption(ToolCommandRestorePassThroughOptions.NoCacheOption); command.AddOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption); command.AddOption(VerbosityOption); + command.AddOption(CommonOptions.ArchitectureOption()); + command.AddOption(CommonOptions.OperatingSystemOption()); return command; } diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf index 951a67947d6f..e464ad014705 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Umožňuje, aby se příkaz zastavil a počkal na vstup nebo akci uživatele (například na dokončení ověření). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" V {0} se našlo několik projektů. Vyberte, který z nich chcete použít. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Projekt už obsahuje odkaz na {0}. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf index 493080b0b040..8f2f27b40cec 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Hiermit wird zugelassen, dass der Befehl anhält und auf eine Benutzereingabe oder Aktion wartet (beispielsweise auf den Abschluss der Authentifizierung). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" In "{0}" wurden mehrere Projekte gefunden. Geben Sie an, welches davon verwendet werden soll. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Für das Projekt ist bereits ein Verweis auf "{0}" vorhanden. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf index 9d607944e847..a2c45d7d28f2 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Permite que el comando se detenga y espere la entrada o acción del usuario (por ejemplo, para autenticarse). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" Se han encontrado varios proyectos en "{0}". Especifique el que debe usarse. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. El proyecto ya tiene una referencia a "{0}". diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf index f24316d351b9..97f8857ccf2b 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Permet à la commande de s'arrêter et d'attendre une entrée ou une action de l'utilisateur (par exemple pour effectuer une authentification). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" Plusieurs projets dans '{0}'. Spécifiez celui à utiliser. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Le projet a déjà une référence à '{0}'. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf index b4a39729943b..d7b94332c6c4 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Consente al comando di arrestare l'esecuzione e attendere l'input o l'azione dell'utente, ad esempio per completare l'autenticazione. @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" Sono stati trovati più progetti in `{0}`. Specificare quello da usare. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Per il progetto esiste già un riferimento a `{0}`. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf index ec5a1ebdbab9..3015dfac7703 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). コマンドを停止して、ユーザーの入力またはアクション (認証の完了など) を待機できるようにします。 @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" `{0}` に複数のプロジェクトが見つかりました。使用するプロジェクトを指定してください。 + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. プロジェクトには既に `{0}` への参照が指定されています。 diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf index 029d37bc5cc9..01a24297d7a8 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). 명령을 중지하고 사용자 입력 또는 작업을 기다리도록 허용합니다(예: 인증 완료). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" '{0}'에서 프로젝트를 두 개 이상 찾았습니다. 사용할 프로젝트를 지정하세요. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. 프로젝트에 이미 '{0}'에 대한 참조가 있습니다. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf index 30a537f25947..d15e513fd283 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Zezwala poleceniu na zatrzymanie działania i zaczekanie na wprowadzenie danych lub wykonanie akcji przez użytkownika (na przykład ukończenie uwierzytelniania). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" Znaleziono więcej niż jeden projekt w lokalizacji „{0}”. Określ, który ma zostać użyty. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Projekt zawiera już odwołanie do elementu „{0}”. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf index 5e5320217a24..0e1e1b43503f 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Permite que o comando seja interrompido e aguarde a ação ou entrada do usuário (por exemplo, para concluir a autenticação). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" Foi encontrado mais de um projeto em ‘{0}’. Especifique qual deve ser usado. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. O projeto já tem uma referência a ‘{0}’. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf index 2e4407d8192e..c5697e8c9bd3 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Позволяет остановить команду и ожидать ввода или действия пользователя (например, для проверки подлинности). @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" Найдено несколько проектов в "{0}". Выберите один. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Проект уже содержит ссылку на "{0}". diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf index 4e24e55d8e79..b26698c8e1a5 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Komutun durup kullanıcı girişini veya eylemini (örneğin, kimlik doğrulamasının tamamlanmasını) beklemesine izin verir . @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" `{0}` içinde birden fazla proje bulundu. Hangisinin kullanılacağını belirtin. + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. Projede `{0}` başvurusu zaten var. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf index 752b5f3af75b..405e2ad39099 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). 允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。 @@ -80,6 +90,11 @@ EOF 在“{0}”中找到多个项目。请指定使用哪一个。 + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. 项目已经具有对“{0}”的引用。 diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf index f103b9bbdf13..719ffa496878 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf @@ -2,6 +2,16 @@ + + The target architecture. + The target architecture. + + + + Resolving the current runtime identifier failed. + Resolving the current runtime identifier failed. + + Allows the command to stop and wait for user input or action (for example to complete authentication). 允許命令停止並等候使用者輸入或動作 (例如: 完成驗證)。 @@ -80,6 +90,11 @@ export PATH="$PATH:{0}" 在 `{0}` 中找到多個專案。請指定要使用的專案。 + + The target operating system. + The target operating system. + + Project already has a reference to `{0}`. 專案已經有 `{0}` 的參考。 diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs index 0aa34445315a..cb0afcb62bc7 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs @@ -4,6 +4,10 @@ using Microsoft.DotNet.Tools.Build; using FluentAssertions; using Xunit; +using Microsoft.DotNet.Cli.Utils; +using System; +using Microsoft.NET.TestFramework; +using Microsoft.DotNet.Tools; namespace Microsoft.DotNet.Cli.MSBuild.Tests { @@ -84,7 +88,33 @@ public void MsbuildInvocationIsCorrectForSeparateRestore( .Should() .Be($"{ExpectedPrefix} -nologo -consoleloggerparameters:Summary{expectedAdditionalArgs}"); }); + } + [Fact] + public void OsOptionIsCorrectlyResolved() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var command = BuildCommand.FromArgs(new string[] { "--os", "os" }, msbuildPath); + var expectedArch = Environment.Is64BitOperatingSystem ? "x64" : "x86"; + command.GetArgumentsToMSBuild() + .Should() + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-{expectedArch} -property:SelfContained=true"); + }); + } + + [WindowsOnlyFact] + public void ArchOptionIsCorrectlyResolved() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var command = BuildCommand.FromArgs(new string[] { "--arch", "arch" }, msbuildPath); + command.GetArgumentsToMSBuild() + .Should() + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=win-arch -property:SelfContained=true"); + }); } } } From 7a2620d9f18e00aa23c9a8d9ec43d2fe321a04b0 Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Thu, 15 Jul 2021 10:06:45 -0700 Subject: [PATCH 2/5] PR feedback --- src/Cli/dotnet/CommonOptions.cs | 34 +++++++++++++++---- src/Cli/dotnet/OptionForwardingExtensions.cs | 10 ++++-- src/Cli/dotnet/ParseResultExtensions.cs | 4 +++ .../GivenDotnetBuildInvocation.cs | 17 ++++++++-- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index 54e906a503ad..412ac0e1b006 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.Cli.Utils; +using System.CommandLine.Parsing; namespace Microsoft.DotNet.Cli { @@ -116,18 +117,33 @@ public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosi verbosity.Equals(VerbosityOptions.detailed); } - internal static IEnumerable ResolveArchOptionToRuntimeIdentifier(string arg) + internal static IEnumerable ResolveArchOptionToRuntimeIdentifier(string arg, ParseResult parseResult) { - var currentRid = GetCurrentRuntimeId(); - var os = currentRid.Substring(0, currentRid.LastIndexOf("-")); - return new string[] { $"-property:RuntimeIdentifier={os}-{arg}", "-property:SelfContained=true" }; + if (parseResult.BothArchAndOsOptionsSpecified()) + { + return Array.Empty(); + } + + return ResolveRidShorthandOptions(null, arg); + } + + internal static IEnumerable ResolveOsOptionToRuntimeIdentifier(string arg, ParseResult parseResult) + { + if (parseResult.BothArchAndOsOptionsSpecified()) + { + return ResolveRidShorthandOptions(arg, parseResult.ValueForOption(CommonOptions.ArchitectureOption().Aliases.First())); + } + + return ResolveRidShorthandOptions(arg, null); } - internal static IEnumerable ResolveOsOptionToRuntimeIdentifier(string arg) + private static IEnumerable ResolveRidShorthandOptions(string os, string arch) { var currentRid = GetCurrentRuntimeId(); - var arch = currentRid.Substring(currentRid.LastIndexOf("-") + 1, currentRid.Length - currentRid.LastIndexOf("-") - 1); - return new string[] { $"-property:RuntimeIdentifier={arg}-{arch}", "-property:SelfContained=true" }; + os = string.IsNullOrEmpty(os) ? GetOsFromRid(currentRid) : os; + arch = string.IsNullOrEmpty(arch) ? GetArchFromRid(currentRid) : arch; + var properties = new string[] { $"-property:RuntimeIdentifier={os}-{arch}" }; + return properties; } private static string GetCurrentRuntimeId() @@ -147,6 +163,10 @@ private static string GetCurrentRuntimeId() } return currentRuntimeIdentifiers[0]; // First rid is the most specific (ex win-x64) } + + private static string GetOsFromRid(string rid) => rid.Substring(0, rid.LastIndexOf("-")); + + private static string GetArchFromRid(string rid) => rid.Substring(rid.LastIndexOf("-") + 1, rid.Length - rid.LastIndexOf("-") - 1); } public enum VerbosityOptions diff --git a/src/Cli/dotnet/OptionForwardingExtensions.cs b/src/Cli/dotnet/OptionForwardingExtensions.cs index 0f2d4df908e8..000fbe40c504 100644 --- a/src/Cli/dotnet/OptionForwardingExtensions.cs +++ b/src/Cli/dotnet/OptionForwardingExtensions.cs @@ -11,9 +11,9 @@ namespace Microsoft.DotNet.Cli { public static class OptionForwardingExtensions { - public static ForwardedOption Forward(this ForwardedOption option) => option.SetForwardingFunction((o) => new string[] { option.Name }); + public static ForwardedOption Forward(this ForwardedOption option) => option.SetForwardingFunction((T o) => new string[] { option.Name }); - public static ForwardedOption ForwardAs(this ForwardedOption option, string value) => option.SetForwardingFunction((o) => new string[] { value }); + public static ForwardedOption ForwardAs(this ForwardedOption option, string value) => option.SetForwardingFunction((T o) => new string[] { value }); public static ForwardedOption ForwardAsSingle(this ForwardedOption option, Func format) => option.SetForwardingFunction(format); @@ -81,6 +81,12 @@ public ForwardedOption SetForwardingFunction(Func format) return this; } + public ForwardedOption SetForwardingFunction(Func> func) + { + ForwardingFunction = (ParseResult parseResult) => parseResult.HasOption(Aliases.First()) ? func(parseResult.ValueForOption(Aliases.First()), parseResult) : Array.Empty(); + return this; + } + public Func> GetForwardingFunction(Func> func) { return (ParseResult parseResult) => parseResult.HasOption(Aliases.First()) ? func(parseResult.ValueForOption(Aliases.First())) : Array.Empty(); diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index 7292d9995461..6a2d252c8748 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -85,5 +85,9 @@ private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult return string.Empty; } } + + public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) => + parseResult.HasOption(CommonOptions.ArchitectureOption().Aliases.First()) && + parseResult.HasOption(CommonOptions.OperatingSystemOption().Aliases.First()); } } diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs index cb0afcb62bc7..7c8f8d0921a4 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs @@ -100,7 +100,7 @@ public void OsOptionIsCorrectlyResolved() var expectedArch = Environment.Is64BitOperatingSystem ? "x64" : "x86"; command.GetArgumentsToMSBuild() .Should() - .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-{expectedArch} -property:SelfContained=true"); + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-{expectedArch}"); }); } @@ -113,7 +113,20 @@ public void ArchOptionIsCorrectlyResolved() var command = BuildCommand.FromArgs(new string[] { "--arch", "arch" }, msbuildPath); command.GetArgumentsToMSBuild() .Should() - .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=win-arch -property:SelfContained=true"); + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=win-arch"); + }); + } + + [Fact] + public void OSAndArchOptionsCanBeCombined() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var command = BuildCommand.FromArgs(new string[] { "--arch", "arch", "--os", "os" }, msbuildPath); + command.GetArgumentsToMSBuild() + .Should() + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-arch"); }); } } From 9c43f940ba86c2f45185eb5003e0b7bc6e04637e Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Mon, 19 Jul 2021 12:55:41 -0700 Subject: [PATCH 3/5] PR feedback --- src/Cli/dotnet/CommonLocalizableStrings.resx | 6 + src/Cli/dotnet/CommonOptions.cs | 20 ++- src/Cli/dotnet/ParseResultExtensions.cs | 9 ++ src/Cli/dotnet/commands/dotnet-run/Program.cs | 2 +- .../install/ToolInstallCommandParser.cs | 2 - .../xlf/CommonLocalizableStrings.cs.xlf | 10 ++ .../xlf/CommonLocalizableStrings.de.xlf | 10 ++ .../xlf/CommonLocalizableStrings.es.xlf | 10 ++ .../xlf/CommonLocalizableStrings.fr.xlf | 10 ++ .../xlf/CommonLocalizableStrings.it.xlf | 10 ++ .../xlf/CommonLocalizableStrings.ja.xlf | 10 ++ .../xlf/CommonLocalizableStrings.ko.xlf | 10 ++ .../xlf/CommonLocalizableStrings.pl.xlf | 10 ++ .../xlf/CommonLocalizableStrings.pt-BR.xlf | 10 ++ .../xlf/CommonLocalizableStrings.ru.xlf | 10 ++ .../xlf/CommonLocalizableStrings.tr.xlf | 10 ++ .../xlf/CommonLocalizableStrings.zh-Hans.xlf | 10 ++ .../xlf/CommonLocalizableStrings.zh-Hant.xlf | 10 ++ .../GivenDotnetBuildInvocation.cs | 44 ------ .../GivenDotnetOsArchOptions.cs | 134 ++++++++++++++++++ 20 files changed, 298 insertions(+), 49 deletions(-) create mode 100644 src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs diff --git a/src/Cli/dotnet/CommonLocalizableStrings.resx b/src/Cli/dotnet/CommonLocalizableStrings.resx index 70501b30e84e..6deec0715801 100644 --- a/src/Cli/dotnet/CommonLocalizableStrings.resx +++ b/src/Cli/dotnet/CommonLocalizableStrings.resx @@ -683,4 +683,10 @@ setx PATH "%PATH%;{0}" Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index 412ac0e1b006..8289295733bb 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -119,8 +119,14 @@ public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosi internal static IEnumerable ResolveArchOptionToRuntimeIdentifier(string arg, ParseResult parseResult) { + if (parseResult.HasOption(RuntimeOption(string.Empty).Aliases.First())) + { + throw new GracefulException(CommonLocalizableStrings.CannotSpecifyBothRuntimeAndArchOptions); + } + if (parseResult.BothArchAndOsOptionsSpecified()) { + // ResolveOsOptionToRuntimeIdentifier handles resolving the RID when both arch and os are specified return Array.Empty(); } @@ -129,6 +135,11 @@ internal static IEnumerable ResolveArchOptionToRuntimeIdentifier(string internal static IEnumerable ResolveOsOptionToRuntimeIdentifier(string arg, ParseResult parseResult) { + if (parseResult.HasOption(RuntimeOption(string.Empty).Aliases.First())) + { + throw new GracefulException(CommonLocalizableStrings.CannotSpecifyBothRuntimeAndOsOptions); + } + if (parseResult.BothArchAndOsOptionsSpecified()) { return ResolveRidShorthandOptions(arg, parseResult.ValueForOption(CommonOptions.ArchitectureOption().Aliases.First())); @@ -138,12 +149,17 @@ internal static IEnumerable ResolveOsOptionToRuntimeIdentifier(string ar } private static IEnumerable ResolveRidShorthandOptions(string os, string arch) + { + var properties = new string[] { $"-property:RuntimeIdentifier={ResolveRidShorthandOptionsToRuntimeIdentifier(os, arch)}" }; + return properties; + } + + internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os, string arch) { var currentRid = GetCurrentRuntimeId(); os = string.IsNullOrEmpty(os) ? GetOsFromRid(currentRid) : os; arch = string.IsNullOrEmpty(arch) ? GetArchFromRid(currentRid) : arch; - var properties = new string[] { $"-property:RuntimeIdentifier={os}-{arch}" }; - return properties; + return $"{os}-{arch}"; } private static string GetCurrentRuntimeId() diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index 6a2d252c8748..ec18434a49a8 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -89,5 +89,14 @@ private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) => parseResult.HasOption(CommonOptions.ArchitectureOption().Aliases.First()) && parseResult.HasOption(CommonOptions.OperatingSystemOption().Aliases.First()); + + internal static string GetCommandLineRuntimeIdentifier(this ParseResult parseResult) + { + return parseResult.HasOption(RunCommandParser.RuntimeOption) ? + parseResult.ValueForOption(RunCommandParser.RuntimeOption) : + CommonOptions.ResolveRidShorthandOptionsToRuntimeIdentifier( + parseResult.ValueForOption(CommonOptions.OperatingSystemOption().Aliases.First()), + parseResult.ValueForOption(CommonOptions.ArchitectureOption().Aliases.First())); + } } } diff --git a/src/Cli/dotnet/commands/dotnet-run/Program.cs b/src/Cli/dotnet/commands/dotnet-run/Program.cs index 81ceac1e8714..fb1d3c314f05 100644 --- a/src/Cli/dotnet/commands/dotnet-run/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-run/Program.cs @@ -35,7 +35,7 @@ public static RunCommand FromArgs(string[] args) var command = new RunCommand( configuration: parseResult.ValueForOption(RunCommandParser.ConfigurationOption), framework: parseResult.ValueForOption(RunCommandParser.FrameworkOption), - runtime: parseResult.ValueForOption(RunCommandParser.RuntimeOption), + runtime: parseResult.GetCommandLineRuntimeIdentifier(), noBuild: parseResult.HasOption(RunCommandParser.NoBuildOption), project: project, launchProfile: parseResult.ValueForOption(RunCommandParser.LaunchProfileOption), diff --git a/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs b/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs index 3d5928f616d8..8197a90ed0c2 100644 --- a/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallCommandParser.cs @@ -55,8 +55,6 @@ public static Command GetCommand() command.AddOption(ToolCommandRestorePassThroughOptions.NoCacheOption); command.AddOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption); command.AddOption(VerbosityOption); - command.AddOption(CommonOptions.ArchitectureOption()); - command.AddOption(CommonOptions.OperatingSystemOption()); return command; } diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf index e464ad014705..38b0b85623f9 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Umožňuje, aby se příkaz zastavil a počkal na vstup nebo akci uživatele (například na dokončení ověření). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf index 8f2f27b40cec..778eda552b58 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Hiermit wird zugelassen, dass der Befehl anhält und auf eine Benutzereingabe oder Aktion wartet (beispielsweise auf den Abschluss der Authentifizierung). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf index a2c45d7d28f2..f2fc03354dbb 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Permite que el comando se detenga y espere la entrada o acción del usuario (por ejemplo, para autenticarse). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf index 97f8857ccf2b..a5fb6ba30e55 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Permet à la commande de s'arrêter et d'attendre une entrée ou une action de l'utilisateur (par exemple pour effectuer une authentification). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf index d7b94332c6c4..038d64df6200 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Consente al comando di arrestare l'esecuzione e attendere l'input o l'azione dell'utente, ad esempio per completare l'autenticazione. diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf index 3015dfac7703..31171bbf281b 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). コマンドを停止して、ユーザーの入力またはアクション (認証の完了など) を待機できるようにします。 diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf index 01a24297d7a8..90511a3eccad 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). 명령을 중지하고 사용자 입력 또는 작업을 기다리도록 허용합니다(예: 인증 완료). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf index d15e513fd283..e5ed5011dc26 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Zezwala poleceniu na zatrzymanie działania i zaczekanie na wprowadzenie danych lub wykonanie akcji przez użytkownika (na przykład ukończenie uwierzytelniania). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf index 0e1e1b43503f..662c7c6bad03 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Permite que o comando seja interrompido e aguarde a ação ou entrada do usuário (por exemplo, para concluir a autenticação). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf index c5697e8c9bd3..7cbcdca1bda9 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Позволяет остановить команду и ожидать ввода или действия пользователя (например, для проверки подлинности). diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf index b26698c8e1a5..9b7d12a5e003 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). Komutun durup kullanıcı girişini veya eylemini (örneğin, kimlik doğrulamasının tamamlanmasını) beklemesine izin verir . diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf index 405e2ad39099..a1d08fa9770f 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). 允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。 diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf index 719ffa496878..be10e0f154eb 100644 --- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf @@ -12,6 +12,16 @@ Resolving the current runtime identifier failed. + + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + Specifying both the `-r|--runtime` and `-a|--arch` options is not supported. + + + + Specifying both the `-r|--runtime` and `-os` options is not supported. + Specifying both the `-r|--runtime` and `-os` options is not supported. + + Allows the command to stop and wait for user input or action (for example to complete authentication). 允許命令停止並等候使用者輸入或動作 (例如: 完成驗證)。 diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs index 7c8f8d0921a4..3f683aabe65a 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs @@ -4,10 +4,6 @@ using Microsoft.DotNet.Tools.Build; using FluentAssertions; using Xunit; -using Microsoft.DotNet.Cli.Utils; -using System; -using Microsoft.NET.TestFramework; -using Microsoft.DotNet.Tools; namespace Microsoft.DotNet.Cli.MSBuild.Tests { @@ -89,45 +85,5 @@ public void MsbuildInvocationIsCorrectForSeparateRestore( .Be($"{ExpectedPrefix} -nologo -consoleloggerparameters:Summary{expectedAdditionalArgs}"); }); } - - [Fact] - public void OsOptionIsCorrectlyResolved() - { - CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => - { - var msbuildPath = ""; - var command = BuildCommand.FromArgs(new string[] { "--os", "os" }, msbuildPath); - var expectedArch = Environment.Is64BitOperatingSystem ? "x64" : "x86"; - command.GetArgumentsToMSBuild() - .Should() - .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-{expectedArch}"); - }); - } - - [WindowsOnlyFact] - public void ArchOptionIsCorrectlyResolved() - { - CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => - { - var msbuildPath = ""; - var command = BuildCommand.FromArgs(new string[] { "--arch", "arch" }, msbuildPath); - command.GetArgumentsToMSBuild() - .Should() - .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=win-arch"); - }); - } - - [Fact] - public void OSAndArchOptionsCanBeCombined() - { - CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => - { - var msbuildPath = ""; - var command = BuildCommand.FromArgs(new string[] { "--arch", "arch", "--os", "os" }, msbuildPath); - command.GetArgumentsToMSBuild() - .Should() - .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-arch"); - }); - } } } diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs new file mode 100644 index 000000000000..ddac1237a45f --- /dev/null +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs @@ -0,0 +1,134 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Xunit; +using Microsoft.DotNet.Cli.Utils; +using System; +using Microsoft.NET.TestFramework; +using Microsoft.DotNet.Tools; +using System.Runtime.InteropServices; +using Xunit.Abstractions; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using BuildCommand = Microsoft.DotNet.Tools.Build.BuildCommand; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetOsArchOptions : SdkTest + { + public GivenDotnetOsArchOptions(ITestOutputHelper log) : base(log) + { + } + + const string ExpectedPrefix = "-maxcpucount -verbosity:m"; + + private static readonly string WorkingDirectory = + TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetBuildInvocation)); + + [Fact] + public void OsOptionIsCorrectlyResolved() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var command = BuildCommand.FromArgs(new string[] { "--os", "os" }, msbuildPath); + var expectedArch = RuntimeInformation.ProcessArchitecture.Equals(Architecture.Arm64) ? "arm64" : Environment.Is64BitOperatingSystem ? "x64" : "x86"; + command.GetArgumentsToMSBuild() + .Should() + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-{expectedArch}"); + }); + } + + [Fact] + public void ArchOptionIsCorrectlyResolved() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var command = BuildCommand.FromArgs(new string[] { "--arch", "arch" }, msbuildPath); + var expectedOs = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win" : + RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux" : + RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx" : + null; + if (expectedOs == null) + { + // Not a supported OS for running test + return; + } + command.GetArgumentsToMSBuild() + .Should() + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier={expectedOs}-arch"); + }); + } + + [Fact] + public void OSAndArchOptionsCanBeCombined() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var command = BuildCommand.FromArgs(new string[] { "--arch", "arch", "--os", "os" }, msbuildPath); + command.GetArgumentsToMSBuild() + .Should() + .Be($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary -property:RuntimeIdentifier=os-arch"); + }); + } + + [Fact] + public void OSOptionCannotBeCombinedWithRuntime() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var exceptionThrown = Assert.Throws(() => BuildCommand.FromArgs(new string[] { "--os", "os", "--runtime", "rid" }, msbuildPath)); + exceptionThrown.Message.Should().Be(CommonLocalizableStrings.CannotSpecifyBothRuntimeAndOsOptions); + }); + } + + [Fact] + public void ArchOptionCannotBeCombinedWithRuntime() + { + CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => + { + var msbuildPath = ""; + var exceptionThrown = Assert.Throws(() => BuildCommand.FromArgs(new string[] { "--arch", "arch", "--runtime", "rid" }, msbuildPath)); + exceptionThrown.Message.Should().Be(CommonLocalizableStrings.CannotSpecifyBothRuntimeAndArchOptions); + }); + } + + [Theory] + [InlineData("build")] + [InlineData("publish")] + [InlineData("test")] + [InlineData("run")] + public void CommandsRunWithOSOption(string command) + { + var testInstance = _testAssetsManager.CopyTestAsset("HelloWorld", identifier: command) + .WithSource(); + + new DotnetCommand(Log) + .WithWorkingDirectory(testInstance.Path) + .Execute(command, "--os", "win") + .Should() + .Pass(); + } + + [Theory] + [InlineData("build")] + [InlineData("publish")] + [InlineData("test")] + [InlineData("run")] + public void CommandsRunWithArchOption(string command) + { + var testInstance = _testAssetsManager.CopyTestAsset("HelloWorld", identifier: command) + .WithSource(); + + new DotnetCommand(Log) + .WithWorkingDirectory(testInstance.Path) + .Execute(command, "--arch", "x86") + .Should() + .Pass(); + } + } +} From 3d453e28aead32d0506e9985d974e25b98862ddb Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Mon, 19 Jul 2021 13:31:46 -0700 Subject: [PATCH 4/5] Account for empty arch and os options --- src/Cli/dotnet/ParseResultExtensions.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Cli/dotnet/ParseResultExtensions.cs b/src/Cli/dotnet/ParseResultExtensions.cs index ec18434a49a8..d6e854ed9def 100644 --- a/src/Cli/dotnet/ParseResultExtensions.cs +++ b/src/Cli/dotnet/ParseResultExtensions.cs @@ -93,10 +93,12 @@ public static bool BothArchAndOsOptionsSpecified(this ParseResult parseResult) = internal static string GetCommandLineRuntimeIdentifier(this ParseResult parseResult) { return parseResult.HasOption(RunCommandParser.RuntimeOption) ? - parseResult.ValueForOption(RunCommandParser.RuntimeOption) : - CommonOptions.ResolveRidShorthandOptionsToRuntimeIdentifier( - parseResult.ValueForOption(CommonOptions.OperatingSystemOption().Aliases.First()), - parseResult.ValueForOption(CommonOptions.ArchitectureOption().Aliases.First())); + parseResult.ValueForOption(RunCommandParser.RuntimeOption) : + parseResult.HasOption(CommonOptions.OperatingSystemOption().Aliases.First()) || parseResult.HasOption(CommonOptions.ArchitectureOption().Aliases.First()) ? + CommonOptions.ResolveRidShorthandOptionsToRuntimeIdentifier( + parseResult.ValueForOption(CommonOptions.OperatingSystemOption().Aliases.First()), + parseResult.ValueForOption(CommonOptions.ArchitectureOption().Aliases.First())) : + null; } } } From 5e88e2e5d0450d6d90d1fdcfd436c554290994a4 Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Wed, 21 Jul 2021 10:37:45 -0700 Subject: [PATCH 5/5] Update rid file testing logic --- src/Cli/dotnet/CommonOptions.cs | 3 ++- .../dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index 8289295733bb..b3b98dab1a73 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -165,7 +165,8 @@ internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os, private static string GetCurrentRuntimeId() { var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath); - dotnetRootPath = dotnetRootPath.Contains("dotnet") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); + // When running under test the path does not always contain "dotnet" and Product.Version is empty. + dotnetRootPath = Path.GetFileName(dotnetRootPath).Contains("dotnet") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); var ridFileName = "NETCoreSdkRuntimeIdentifierChain.txt"; string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) ? Path.Combine(Directory.GetDirectories(Path.Combine(dotnetRootPath, "sdk"))[0], ridFileName) : diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs index ddac1237a45f..02cb2e7f0ad1 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs @@ -97,7 +97,7 @@ public void ArchOptionCannotBeCombinedWithRuntime() }); } - [Theory] + [WindowsOnlyTheory] [InlineData("build")] [InlineData("publish")] [InlineData("test")] @@ -114,7 +114,7 @@ public void CommandsRunWithOSOption(string command) .Pass(); } - [Theory] + [WindowsOnlyTheory] [InlineData("build")] [InlineData("publish")] [InlineData("test")]