diff --git a/src/Cli/dotnet/CommonLocalizableStrings.resx b/src/Cli/dotnet/CommonLocalizableStrings.resx
index 4b87b84ac643..6deec0715801 100644
--- a/src/Cli/dotnet/CommonLocalizableStrings.resx
+++ b/src/Cli/dotnet/CommonLocalizableStrings.resx
@@ -674,4 +674,19 @@ 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.
+
+
+ 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 d3ec86e24bf6..b3b98dab1a73 100644
--- a/src/Cli/dotnet/CommonOptions.cs
+++ b/src/Cli/dotnet/CommonOptions.cs
@@ -6,6 +6,10 @@
using System.CommandLine;
using System.IO;
using Microsoft.DotNet.Tools.Common;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.DotNet.Cli.Utils;
+using System.CommandLine.Parsing;
namespace Microsoft.DotNet.Cli
{
@@ -35,7 +39,7 @@ public static Option FrameworkOption(string description) =>
description)
{
ArgumentHelpName = CommonLocalizableStrings.FrameworkArgumentName
-
+
}.ForwardAsSingle(o => $"-property:TargetFramework={o}")
.AddSuggestions(Suggest.TargetFrameworksFromProjectFile());
@@ -91,6 +95,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 +116,74 @@ public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosi
verbosity.Equals(VerbosityOptions.d) ||
verbosity.Equals(VerbosityOptions.detailed);
}
+
+ 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();
+ }
+
+ return ResolveRidShorthandOptions(null, arg);
+ }
+
+ 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()));
+ }
+
+ return ResolveRidShorthandOptions(arg, null);
+ }
+
+ 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;
+ return $"{os}-{arch}";
+ }
+
+ private static string GetCurrentRuntimeId()
+ {
+ var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath);
+ // 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) :
+ 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)
+ }
+
+ 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..d6e854ed9def 100644
--- a/src/Cli/dotnet/ParseResultExtensions.cs
+++ b/src/Cli/dotnet/ParseResultExtensions.cs
@@ -85,5 +85,20 @@ 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());
+
+ internal static string GetCommandLineRuntimeIdentifier(this ParseResult parseResult)
+ {
+ return parseResult.HasOption(RunCommandParser.RuntimeOption) ?
+ 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;
+ }
}
}
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/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-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/xlf/CommonLocalizableStrings.cs.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf
index 951a67947d6f..38b0b85623f9 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
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 +100,11 @@ export PATH="$PATH:{0}"
V {0} se našlo několik projektů. Vyberte, který z nich chcete použít.
+
+
+ The target operating system.
+
+
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..778eda552b58 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
Hiermit wird zugelassen, dass der Befehl anhält und auf eine Benutzereingabe oder Aktion wartet (beispielsweise auf den Abschluss der Authentifizierung).
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
In "{0}" wurden mehrere Projekte gefunden. Geben Sie an, welches davon verwendet werden soll.
+
+
+ The target operating system.
+
+
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..f2fc03354dbb 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
Permite que el comando se detenga y espere la entrada o acción del usuario (por ejemplo, para autenticarse).
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
Se han encontrado varios proyectos en "{0}". Especifique el que debe usarse.
+
+
+ The target operating system.
+
+
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..a5fb6ba30e55 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
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 +100,11 @@ export PATH="$PATH:{0}"
Plusieurs projets dans '{0}'. Spécifiez celui à utiliser.
+
+
+ The target operating system.
+
+
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..038d64df6200 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
Consente al comando di arrestare l'esecuzione e attendere l'input o l'azione dell'utente, ad esempio per completare l'autenticazione.
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
Sono stati trovati più progetti in `{0}`. Specificare quello da usare.
+
+
+ The target operating system.
+
+
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..31171bbf281b 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
コマンドを停止して、ユーザーの入力またはアクション (認証の完了など) を待機できるようにします。
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
`{0}` に複数のプロジェクトが見つかりました。使用するプロジェクトを指定してください。
+
+
+ The target operating system.
+
+
プロジェクトには既に `{0}` への参照が指定されています。
diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf
index 029d37bc5cc9..90511a3eccad 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
명령을 중지하고 사용자 입력 또는 작업을 기다리도록 허용합니다(예: 인증 완료).
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
'{0}'에서 프로젝트를 두 개 이상 찾았습니다. 사용할 프로젝트를 지정하세요.
+
+
+ The target operating system.
+
+
프로젝트에 이미 '{0}'에 대한 참조가 있습니다.
diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf
index 30a537f25947..e5ed5011dc26 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pl.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
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 +100,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.
+
+
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..662c7c6bad03 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.pt-BR.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
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 +100,11 @@ export PATH="$PATH:{0}"
Foi encontrado mais de um projeto em ‘{0}’. Especifique qual deve ser usado.
+
+
+ The target operating system.
+
+
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..7cbcdca1bda9 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.ru.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
Позволяет остановить команду и ожидать ввода или действия пользователя (например, для проверки подлинности).
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
Найдено несколько проектов в "{0}". Выберите один.
+
+
+ The target operating system.
+
+
Проект уже содержит ссылку на "{0}".
diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf
index 4e24e55d8e79..9b7d12a5e003 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.tr.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
Komutun durup kullanıcı girişini veya eylemini (örneğin, kimlik doğrulamasının tamamlanmasını) beklemesine izin verir .
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
`{0}` içinde birden fazla proje bulundu. Hangisinin kullanılacağını belirtin.
+
+
+ The target operating system.
+
+
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..a1d08fa9770f 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
允许命令停止和等待用户输入或操作(例如,用以完成身份验证)。
@@ -80,6 +100,11 @@ EOF
在“{0}”中找到多个项目。请指定使用哪一个。
+
+
+ The target operating system.
+
+
项目已经具有对“{0}”的引用。
diff --git a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf
index f103b9bbdf13..be10e0f154eb 100644
--- a/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf
+++ b/src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hant.xlf
@@ -2,6 +2,26 @@
+
+
+ The target architecture.
+
+
+
+
+ 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.
+
+
允許命令停止並等候使用者輸入或動作 (例如: 完成驗證)。
@@ -80,6 +100,11 @@ export PATH="$PATH:{0}"
在 `{0}` 中找到多個專案。請指定要使用的專案。
+
+
+ The target operating system.
+
+
專案已經有 `{0}` 的參考。
diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs
index 0aa34445315a..3f683aabe65a 100644
--- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs
+++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs
@@ -84,7 +84,6 @@ public void MsbuildInvocationIsCorrectForSeparateRestore(
.Should()
.Be($"{ExpectedPrefix} -nologo -consoleloggerparameters:Summary{expectedAdditionalArgs}");
});
-
}
}
}
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..02cb2e7f0ad1
--- /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);
+ });
+ }
+
+ [WindowsOnlyTheory]
+ [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();
+ }
+
+ [WindowsOnlyTheory]
+ [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();
+ }
+ }
+}