diff --git a/src/Cli/dotnet/CommonLocalizableStrings.resx b/src/Cli/dotnet/CommonLocalizableStrings.resx
index 6deec0715801..c5a8fc30e679 100644
--- a/src/Cli/dotnet/CommonLocalizableStrings.resx
+++ b/src/Cli/dotnet/CommonLocalizableStrings.resx
@@ -689,4 +689,14 @@ setx PATH "%PATH%;{0}"
Specifying both the `-r|--runtime` and `-os` options is not supported.
+
+ Publish the .NET runtime with your application so the runtime doesn't need to be installed on the target machine.
+The default is 'true' if a runtime identifier is specified.
+
+
+ Publish your application as a framework dependent application. A compatible .NET runtime must be installed on the target machine to run your application.
+
+
+ The '--self-contained' and '--no-self-contained' options cannot be used together.
+
diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs
index b3b98dab1a73..345bfc2aed65 100644
--- a/src/Cli/dotnet/CommonOptions.cs
+++ b/src/Cli/dotnet/CommonOptions.cs
@@ -49,7 +49,7 @@ public static Option RuntimeOption(string description, bool withShortOption = tr
description)
{
ArgumentHelpName = CommonLocalizableStrings.RuntimeIdentifierArgumentName
- }.ForwardAsSingle(o => $"-property:RuntimeIdentifier={o}")
+ }.ForwardAsMany(o => new string[] { $"-property:RuntimeIdentifier={o}", "-property:_CommandLineDefinedRuntimeIdentifier=true" })
.AddSuggestions(Suggest.RunTimesFromProjectFile());
public static Option CurrentRuntimeOption(string description) =>
@@ -109,6 +109,18 @@ public static Option OperatingSystemOption() =>
public static Option DebugOption() => new Option("--debug");
+ public static Option SelfContainedOption() =>
+ new ForwardedOption(
+ "--self-contained",
+ CommonLocalizableStrings.SelfContainedOptionDescription)
+ .ForwardAsMany(o => new string[] { $"-property:SelfContained={o}", "-property:_CommandLineDefinedSelfContained=true" });
+
+ public static Option NoSelfContainedOption() =>
+ new ForwardedOption(
+ "--no-self-contained",
+ CommonLocalizableStrings.FrameworkDependentOptionDescription)
+ .ForwardAsMany(o => new string[] { "-property:SelfContained=false", "-property:_CommandLineDefinedSelfContained=true" });
+
public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosity)
{
return verbosity.Equals(VerbosityOptions.diag) ||
@@ -117,6 +129,14 @@ public static bool VerbosityIsDetailedOrDiagnostic(this VerbosityOptions verbosi
verbosity.Equals(VerbosityOptions.detailed);
}
+ public static void ValidateSelfContainedOptions(bool hasSelfContainedOption, bool hasNoSelfContainedOption)
+ {
+ if (hasSelfContainedOption && hasNoSelfContainedOption)
+ {
+ throw new GracefulException(CommonLocalizableStrings.SelfContainAndNoSelfContainedConflict);
+ }
+ }
+
internal static IEnumerable ResolveArchOptionToRuntimeIdentifier(string arg, ParseResult parseResult)
{
if (parseResult.HasOption(RuntimeOption(string.Empty).Aliases.First()))
diff --git a/src/Cli/dotnet/commands/dotnet-build/BuildCommand.cs b/src/Cli/dotnet/commands/dotnet-build/BuildCommand.cs
index 224e380cf45e..5c9e8a0a0b34 100644
--- a/src/Cli/dotnet/commands/dotnet-build/BuildCommand.cs
+++ b/src/Cli/dotnet/commands/dotnet-build/BuildCommand.cs
@@ -7,7 +7,6 @@
using Parser = Microsoft.DotNet.Cli.Parser;
using System.CommandLine.Parsing;
using System;
-using System.Linq;
namespace Microsoft.DotNet.Tools.Build
{
@@ -33,6 +32,9 @@ public static BuildCommand FromArgs(string[] args, string msbuildPath = null)
parseResult.ShowHelpOrErrorIfAppropriate();
+ CommonOptions.ValidateSelfContainedOptions(parseResult.HasOption(BuildCommandParser.SelfContainedOption),
+ parseResult.HasOption(BuildCommandParser.NoSelfContainedOption));
+
msbuildArgs.Add($"-consoleloggerparameters:Summary");
if (parseResult.HasOption(BuildCommandParser.NoIncrementalOption))
diff --git a/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs
index 5a4adc5e6cf2..1ff042235022 100644
--- a/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs
+++ b/src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs
@@ -31,6 +31,12 @@ internal static class BuildCommandParser
public static readonly Option NoRestoreOption = CommonOptions.NoRestoreOption();
+ public static readonly Option SelfContainedOption = CommonOptions.SelfContainedOption();
+
+ public static readonly Option NoSelfContainedOption = CommonOptions.NoSelfContainedOption();
+
+ public static readonly Option RuntimeOption = CommonOptions.RuntimeOption(LocalizableStrings.RuntimeOptionDescription);
+
public static Command GetCommand()
{
var command = new Command("build", LocalizableStrings.AppFullName);
@@ -39,7 +45,7 @@ public static Command GetCommand()
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: false);
command.AddOption(CommonOptions.FrameworkOption(LocalizableStrings.FrameworkOptionDescription));
command.AddOption(CommonOptions.ConfigurationOption(LocalizableStrings.ConfigurationOptionDescription));
- command.AddOption(CommonOptions.RuntimeOption(LocalizableStrings.RuntimeOptionDescription));
+ command.AddOption(RuntimeOption);
command.AddOption(CommonOptions.VersionSuffixOption());
command.AddOption(NoRestoreOption);
command.AddOption(CommonOptions.InteractiveMsBuildForwardOption());
@@ -49,7 +55,9 @@ public static Command GetCommand()
command.AddOption(NoIncrementalOption);
command.AddOption(NoDependenciesOption);
command.AddOption(NoLogoOption);
- command.AddOption(CommonOptions.ArchitectureOption());
+ command.AddOption(SelfContainedOption);
+ command.AddOption(NoSelfContainedOption);
+ command.AddOption(CommonOptions.ArchitectureOption());
command.AddOption(CommonOptions.OperatingSystemOption());
return command;
diff --git a/src/Cli/dotnet/commands/dotnet-publish/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-publish/LocalizableStrings.resx
index afe5d1ae9bd4..4cf239b7dde9 100644
--- a/src/Cli/dotnet/commands/dotnet-publish/LocalizableStrings.resx
+++ b/src/Cli/dotnet/commands/dotnet-publish/LocalizableStrings.resx
@@ -135,10 +135,6 @@
The path to a target manifest file that contains the list of packages to be excluded from the publish step.
-
- Publish the .NET runtime with your application so the runtime doesn't need to be installed on the target machine.
-The default is 'true' if a runtime identifier is specified.
-
Do not build the project before publishing. Implies --no-restore.
@@ -155,10 +151,4 @@ The default is to publish a framework-dependent application.
Do not display the startup banner or the copyright message.
-
- Publish your application as a framework dependent application without the .NET runtime. A supported .NET runtime must be installed to run your application.
-
-
- The '--self-contained' and '--no-self-contained' options conflict with each other. Specify only one of the options.
-
diff --git a/src/Cli/dotnet/commands/dotnet-publish/Program.cs b/src/Cli/dotnet/commands/dotnet-publish/Program.cs
index 1ba71ef0a2c9..40fbb1637421 100644
--- a/src/Cli/dotnet/commands/dotnet-publish/Program.cs
+++ b/src/Cli/dotnet/commands/dotnet-publish/Program.cs
@@ -35,11 +35,8 @@ public static PublishCommand FromArgs(string[] args, string msbuildPath = null)
msbuildArgs.Add("-target:Publish");
- if (parseResult.HasOption(PublishCommandParser.SelfContainedOption) &&
- parseResult.HasOption(PublishCommandParser.NoSelfContainedOption))
- {
- throw new GracefulException(LocalizableStrings.SelfContainAndNoSelfContainedConflict);
- }
+ CommonOptions.ValidateSelfContainedOptions(parseResult.HasOption(PublishCommandParser.SelfContainedOption),
+ parseResult.HasOption(PublishCommandParser.NoSelfContainedOption));
msbuildArgs.AddRange(parseResult.OptionValuesToBeForwarded(PublishCommandParser.GetCommand()));
diff --git a/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs
index 6344de64f300..09e3ceed97c0 100644
--- a/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs
+++ b/src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs
@@ -31,17 +31,17 @@ internal static class PublishCommandParser
public static readonly Option NoBuildOption = new ForwardedOption("--no-build", LocalizableStrings.NoBuildOptionDescription)
.ForwardAs("-property:NoBuild=true");
- public static readonly Option SelfContainedOption = new ForwardedOption("--self-contained", LocalizableStrings.SelfContainedOptionDescription)
- .ForwardAsSingle(o => $"-property:SelfContained={o}");
-
- public static readonly Option NoSelfContainedOption = new ForwardedOption("--no-self-contained", LocalizableStrings.NoSelfContainedOptionDescription)
- .ForwardAs("-property:SelfContained=false");
-
public static readonly Option NoLogoOption = new ForwardedOption("--nologo", LocalizableStrings.CmdNoLogo)
.ForwardAs("-nologo");
public static readonly Option NoRestoreOption = CommonOptions.NoRestoreOption();
+ public static readonly Option SelfContainedOption = CommonOptions.SelfContainedOption();
+
+ public static readonly Option NoSelfContainedOption = CommonOptions.NoSelfContainedOption();
+
+ public static readonly Option RuntimeOption = CommonOptions.RuntimeOption(LocalizableStrings.RuntimeOptionDescription);
+
public static Command GetCommand()
{
var command = new Command("publish", LocalizableStrings.AppDescription);
@@ -55,7 +55,7 @@ public static Command GetCommand()
command.AddOption(NoSelfContainedOption);
command.AddOption(NoLogoOption);
command.AddOption(CommonOptions.FrameworkOption(LocalizableStrings.FrameworkOptionDescription));
- command.AddOption(CommonOptions.RuntimeOption(LocalizableStrings.RuntimeOptionDescription));
+ command.AddOption(RuntimeOption);
command.AddOption(CommonOptions.ConfigurationOption(LocalizableStrings.ConfigurationOptionDescription));
command.AddOption(CommonOptions.VersionSuffixOption());
command.AddOption(CommonOptions.InteractiveMsBuildForwardOption());
diff --git a/src/Cli/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf
index 9cd8a9022177..2f8acca4af7f 100644
--- a/src/Cli/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf
+++ b/src/Cli/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf
@@ -22,11 +22,6 @@
Cílová architektura pro publikování. Cílová architektura musí být zadaná v souboru projektu.
-
- Publish your application as a framework dependent application without the .NET runtime. A supported .NET runtime must be installed to run your application.
- Publikujte svoji aplikaci jako aplikaci závislou na architektuře bez modulu runtime .NET. Aby bylo možné vaši aplikaci spustit, musí být nainstalovaný podporovaný modul runtime .NET.
-
- OUTPUT_DIROUTPUT_DIR
@@ -64,18 +59,6 @@ Ve výchozím nastavení je publikována aplikace závislá na architektuře.Konfigurace pro publikování. Výchozí možností pro většinu projektů je Debug.
-
- The '--self-contained' and '--no-self-contained' options conflict with each other. Specify only one of the options.
- Možnosti --self-contained a --no-self-contained jsou vzájemně konfliktní. Zadejte pouze jednu z nich.
-
-
-
- Publish the .NET runtime with your application so the runtime doesn't need to be installed on the target machine.
-The default is 'true' if a runtime identifier is specified.
- Publikujte se svou aplikací modul runtime pro .NET, aby ho nebylo nutné instalovat na cílovém počítači.
-Pokud se zadá identifikátor modulu runtime, výchozí hodnota je true.
-
-