Migrate dotnet-pack
This commit is contained in:
parent
4912e4aa6c
commit
120d28a78d
2 changed files with 43 additions and 127 deletions
|
@ -19,112 +19,26 @@ namespace Microsoft.DotNet.Tools.Pack
|
||||||
|
|
||||||
public static PackCommand FromArgs(string[] args, string msbuildPath = null)
|
public static PackCommand FromArgs(string[] args, string msbuildPath = null)
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
var msbuildArgs = new List<string>();
|
||||||
|
|
||||||
CommandLineApplication cmd = new CommandLineApplication(throwOnUnexpectedArg: false)
|
var parser = Parser.Instance;
|
||||||
|
|
||||||
|
var result = parser.ParseFrom("dotnet pack", args);
|
||||||
|
|
||||||
|
Reporter.Output.WriteLine(result.Diagram());
|
||||||
|
|
||||||
|
result.ShowHelpIfRequested();
|
||||||
|
|
||||||
|
var parsedPack = result["dotnet"]["pack"];
|
||||||
|
|
||||||
|
var msbuildArgs = new List<string>()
|
||||||
{
|
{
|
||||||
Name = "pack",
|
"/t:pack"
|
||||||
FullName = LocalizableStrings.AppFullName,
|
|
||||||
Description = LocalizableStrings.AppDescription,
|
|
||||||
HandleRemainingArguments = true,
|
|
||||||
ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cmd.HelpOption("-h|--help");
|
msbuildArgs.AddRange(parsedPack.OptionValuesToBeForwarded());
|
||||||
|
|
||||||
var output = cmd.Option(
|
msbuildArgs.AddRange(parsedPack.Arguments);
|
||||||
$"-o|--output <{LocalizableStrings.CmdOutputDir}>",
|
|
||||||
LocalizableStrings.CmdOutputDirDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
var noBuild = cmd.Option(
|
|
||||||
"--no-build",
|
|
||||||
LocalizableStrings.CmdNoBuildOptionDescription,
|
|
||||||
CommandOptionType.NoValue);
|
|
||||||
var includeSymbols = cmd.Option(
|
|
||||||
"--include-symbols",
|
|
||||||
LocalizableStrings.CmdIncludeSymbolsDescription,
|
|
||||||
CommandOptionType.NoValue);
|
|
||||||
var includeSource = cmd.Option(
|
|
||||||
"--include-source",
|
|
||||||
LocalizableStrings.CmdIncludeSourceDescription,
|
|
||||||
CommandOptionType.NoValue);
|
|
||||||
var configuration = cmd.Option(
|
|
||||||
$"-c|--configuration <{LocalizableStrings.CmdConfig}>",
|
|
||||||
LocalizableStrings.CmdConfigDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
var versionSuffix = cmd.Option(
|
|
||||||
$"--version-suffix <{LocalizableStrings.CmdVersionSuffix}>",
|
|
||||||
LocalizableStrings.CmdVersionSuffixDescription,
|
|
||||||
CommandOptionType.SingleValue);
|
|
||||||
var serviceable = cmd.Option(
|
|
||||||
"-s|--serviceable",
|
|
||||||
LocalizableStrings.CmdServiceableDescription,
|
|
||||||
CommandOptionType.NoValue);
|
|
||||||
var argRoot = cmd.Argument(
|
|
||||||
$"<{LocalizableStrings.CmdArgumentProject}>",
|
|
||||||
LocalizableStrings.CmdArgumentDescription,
|
|
||||||
multipleValues:true);
|
|
||||||
CommandOption verbosityOption = AddVerbosityOption(cmd);
|
|
||||||
|
|
||||||
List<string> msbuildArgs = null;
|
|
||||||
cmd.OnExecute(() =>
|
|
||||||
{
|
|
||||||
msbuildArgs = new List<string>()
|
|
||||||
{
|
|
||||||
"/t:pack"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (noBuild.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:NoBuild=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includeSymbols.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:IncludeSymbols=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includeSource.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:IncludeSource=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:PackageOutputPath={output.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configuration.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:Configuration={configuration.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionSuffix.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:VersionSuffix={versionSuffix.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serviceable.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/p:Serviceable=true");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbosityOption.HasValue())
|
|
||||||
{
|
|
||||||
msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
msbuildArgs.AddRange(argRoot.Values);
|
|
||||||
|
|
||||||
msbuildArgs.AddRange(cmd.RemainingArguments);
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
int exitCode = cmd.Execute(args);
|
|
||||||
if (msbuildArgs == null)
|
|
||||||
{
|
|
||||||
throw new CommandCreationException(exitCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PackCommand(msbuildArgs, msbuildPath);
|
return new PackCommand(msbuildArgs, msbuildPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,40 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
|
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli
|
namespace Microsoft.DotNet.Cli
|
||||||
{
|
{
|
||||||
internal static class PackCommandParser
|
internal static class PackCommandParser
|
||||||
{
|
{
|
||||||
public static Command Pack() =>
|
public static Command Pack() =>
|
||||||
Create.Command("pack",
|
Create.Command(
|
||||||
".NET Core NuGet Package Packer",
|
"pack",
|
||||||
CommonOptions.HelpOption(),
|
LocalizableStrings.AppDescription,
|
||||||
Create.Option("-o|--output",
|
Accept.ZeroOrMoreArguments,
|
||||||
"Directory in which to place built packages.",
|
CommonOptions.HelpOption(),
|
||||||
Accept.ExactlyOneArgument
|
Create.Option(
|
||||||
.With(name: "OUTPUT_DIR")),
|
"-o|--output",
|
||||||
Create.Option("--no-build",
|
LocalizableStrings.CmdOutputDirDescription,
|
||||||
"Skip building the project prior to packing. By default, the project will be built."),
|
Accept.ExactlyOneArgument
|
||||||
Create.Option("--include-symbols",
|
.With(name: LocalizableStrings.CmdOutputDir)
|
||||||
"Include packages with symbols in addition to regular packages in output directory."),
|
.ForwardAs(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
|
||||||
Create.Option("--include-source",
|
Create.Option("--no-build",
|
||||||
"Include PDBs and source files. Source files go into the src folder in the resulting nuget package"),
|
LocalizableStrings.CmdNoBuildOptionDescription,
|
||||||
Create.Option("-c|--configuration",
|
Accept.NoArguments.ForwardAs("/p:NoBuild=true")),
|
||||||
"Configuration to use for building the project. Default for most projects is \"Debug\".",
|
Create.Option("--include-symbols",
|
||||||
Accept.ExactlyOneArgument
|
LocalizableStrings.CmdIncludeSymbolsDescription,
|
||||||
.With(name: "CONFIGURATION")
|
Accept.NoArguments.ForwardAs("/p:IncludeSymbols=true")),
|
||||||
.WithSuggestionsFrom("DEBUG",
|
Create.Option("--include-source",
|
||||||
"RELEASE")),
|
LocalizableStrings.CmdIncludeSourceDescription,
|
||||||
Create.Option("--version-suffix",
|
Accept.NoArguments.ForwardAs("/p:IncludeSource=true")),
|
||||||
"Defines the value for the $(VersionSuffix) property in the project.",
|
CommonOptions.ConfigurationOption(),
|
||||||
Accept.ExactlyOneArgument
|
CommonOptions.VersionSuffixOption(),
|
||||||
.With(name: "VERSION_SUFFIX")),
|
Create.Option("-s|--serviceable",
|
||||||
Create.Option("-s|--serviceable",
|
LocalizableStrings.CmdServiceableDescription,
|
||||||
"Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."),
|
Accept.NoArguments.ForwardAs("/p:Serviceable=true")),
|
||||||
CommonOptions.VerbosityOption());
|
CommonOptions.VerbosityOption());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue