2015-11-16 11:21:57 -08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2017-02-22 12:45:11 -08:00
|
|
|
|
using Microsoft.DotNet.Cli;
|
2016-04-19 22:51:32 -05:00
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-11-15 11:56:39 -08:00
|
|
|
|
using Microsoft.DotNet.Tools.MSBuild;
|
2017-02-22 12:45:11 -08:00
|
|
|
|
using System.Diagnostics;
|
2015-10-06 10:46:43 -07:00
|
|
|
|
|
2015-10-07 14:39:36 -07:00
|
|
|
|
namespace Microsoft.DotNet.Tools.Publish
|
2015-10-06 10:46:43 -07:00
|
|
|
|
{
|
2016-01-30 21:47:50 -08:00
|
|
|
|
public partial class PublishCommand
|
2015-10-06 10:46:43 -07:00
|
|
|
|
{
|
2017-02-22 12:45:11 -08:00
|
|
|
|
public static PublishCommand FromArgs(string[] args, string msbuildPath = null)
|
2015-10-06 10:46:43 -07:00
|
|
|
|
{
|
2015-10-13 14:31:29 -07:00
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
2015-10-06 10:46:43 -07:00
|
|
|
|
app.Name = "dotnet publish";
|
2016-11-30 09:04:04 -08:00
|
|
|
|
app.FullName = LocalizableStrings.AppFullName;
|
|
|
|
|
app.Description = LocalizableStrings.AppDescription;
|
2016-12-19 22:11:39 -08:00
|
|
|
|
app.HandleRemainingArguments = true;
|
2016-10-27 18:46:43 -07:00
|
|
|
|
app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText;
|
2015-10-06 10:46:43 -07:00
|
|
|
|
app.HelpOption("-h|--help");
|
|
|
|
|
|
2016-11-30 09:04:04 -08:00
|
|
|
|
CommandArgument projectArgument = app.Argument($"<{LocalizableStrings.ProjectArgument}>",
|
|
|
|
|
LocalizableStrings.ProjectArgDescription);
|
2015-10-06 10:46:43 -07:00
|
|
|
|
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOption frameworkOption = app.Option(
|
2016-11-30 09:04:04 -08:00
|
|
|
|
$"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription,
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption runtimeOption = app.Option(
|
2016-11-30 09:04:04 -08:00
|
|
|
|
$"-r|--runtime <{LocalizableStrings.RuntimeOption}>", LocalizableStrings.RuntimeOptionDescription,
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption outputOption = app.Option(
|
2016-11-30 09:04:04 -08:00
|
|
|
|
$"-o|--output <{LocalizableStrings.OutputOption}>", LocalizableStrings.OutputOptionDescription,
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOptionType.SingleValue);
|
2015-12-02 23:32:27 -08:00
|
|
|
|
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOption configurationOption = app.Option(
|
2016-11-30 09:04:04 -08:00
|
|
|
|
$"-c|--configuration <{LocalizableStrings.ConfigurationOption}>", LocalizableStrings.ConfigurationOptionDescription,
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOptionType.SingleValue);
|
2016-02-03 10:57:25 -08:00
|
|
|
|
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOption versionSuffixOption = app.Option(
|
2016-11-30 09:04:04 -08:00
|
|
|
|
$"--version-suffix <{LocalizableStrings.VersionSuffixOption}>", LocalizableStrings.VersionSuffixOptionDescription,
|
2016-10-27 18:46:43 -07:00
|
|
|
|
CommandOptionType.SingleValue);
|
2017-01-25 18:57:14 -08:00
|
|
|
|
|
|
|
|
|
CommandOption filterProjOption = app.Option(
|
|
|
|
|
$"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
2016-11-15 11:56:39 -08:00
|
|
|
|
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
2016-04-22 15:01:56 -07:00
|
|
|
|
|
2017-02-22 12:45:11 -08:00
|
|
|
|
var publish = new PublishCommand(msbuildPath);
|
|
|
|
|
bool commandExecuted = false;
|
2016-10-27 18:46:43 -07:00
|
|
|
|
app.OnExecute(() =>
|
|
|
|
|
{
|
2017-02-22 12:45:11 -08:00
|
|
|
|
commandExecuted = true;
|
2016-10-27 18:46:43 -07:00
|
|
|
|
publish.ProjectPath = projectArgument.Value;
|
|
|
|
|
publish.Framework = frameworkOption.Value();
|
|
|
|
|
publish.Runtime = runtimeOption.Value();
|
|
|
|
|
publish.OutputPath = outputOption.Value();
|
|
|
|
|
publish.Configuration = configurationOption.Value();
|
|
|
|
|
publish.VersionSuffix = versionSuffixOption.Value();
|
2017-01-25 18:57:14 -08:00
|
|
|
|
publish.FilterProject = filterProjOption.Value();
|
2016-11-15 11:56:39 -08:00
|
|
|
|
publish.Verbosity = verbosityOption.Value();
|
2016-10-27 18:46:43 -07:00
|
|
|
|
publish.ExtraMSBuildArguments = app.RemainingArguments;
|
2015-11-29 00:14:30 -08:00
|
|
|
|
|
2017-02-22 12:45:11 -08:00
|
|
|
|
return 0;
|
2015-10-06 10:46:43 -07:00
|
|
|
|
});
|
|
|
|
|
|
2017-02-22 12:45:11 -08:00
|
|
|
|
int exitCode = app.Execute(args);
|
|
|
|
|
if (!commandExecuted)
|
|
|
|
|
{
|
|
|
|
|
throw new CommandCreationException(exitCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return publish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int Run(string[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
|
|
|
|
PublishCommand cmd;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
cmd = FromArgs(args);
|
|
|
|
|
}
|
|
|
|
|
catch (CommandCreationException e)
|
|
|
|
|
{
|
|
|
|
|
return e.ExitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cmd.Execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProcessStartInfo GetProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
return CreateForwardingApp(_msbuildPath).GetProcessStartInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Execute()
|
|
|
|
|
{
|
|
|
|
|
return GetProcessStartInfo().Execute();
|
2015-10-06 10:46:43 -07:00
|
|
|
|
}
|
2016-10-27 18:46:43 -07:00
|
|
|
|
}
|
2015-10-06 10:46:43 -07:00
|
|
|
|
}
|