public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var app = new CommandLineApplication(); app.Name = "dotnet publish"; app.FullName = ".NET Publisher"; app.Description = "Publisher for the .NET Platform"; app.HelpOption("-h|--help"); var framework = app.Option("-f|--framework <FRAMEWORK>", "Target framework to compile for", CommandOptionType.SingleValue); var runtime = app.Option("-r|--runtime <RUNTIME_IDENTIFIER>", "Target runtime to publish for", CommandOptionType.SingleValue); var buildBasePath = app.Option("-b|--build-base-path <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue); var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue); var versionSuffix = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines what `*` should be replaced with in version field in project.json", CommandOptionType.SingleValue); var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue); var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory"); var nativeSubdirectories = app.Option("--native-subdirectory", "Temporary mechanism to include subdirectories from native assets of dependency packages in output", CommandOptionType.NoValue); var noBuild = app.Option("--no-build", "Do not build projects before publishing", CommandOptionType.NoValue); app.OnExecute(() => { var publish = new PublishCommand(); publish.Framework = framework.Value(); publish.Runtime = runtime.Value(); publish.BuildBasePath = buildBasePath.Value(); publish.OutputPath = output.Value(); publish.Configuration = configuration.Value() ?? Constants.DefaultConfiguration; publish.NativeSubdirectories = nativeSubdirectories.HasValue(); publish.ProjectPath = projectPath.Value; publish.VersionSuffix = versionSuffix.Value(); publish.ShouldBuild = !noBuild.HasValue(); if (string.IsNullOrEmpty(publish.ProjectPath)) { publish.ProjectPath = Directory.GetCurrentDirectory(); } if (!publish.TryPrepareForPublish()) { return 1; } publish.PublishAllProjects(); Reporter.Output.WriteLine($"Published {publish.NumberOfPublishedProjects}/{publish.NumberOfProjects} projects successfully"); return (publish.NumberOfPublishedProjects == publish.NumberOfProjects) ? 0 : 1; }); try { return app.Execute(args); } catch (Exception ex) { Reporter.Error.WriteLine(ex.Message.Red()); Reporter.Verbose.WriteLine(ex.ToString().Yellow()); return 1; } }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var app = new CommandLineApplication(); app.Name = "dotnet publish"; app.FullName = ".NET Publisher"; app.Description = "Publisher for the .NET Platform"; app.HelpOption("-h|--help"); var framework = app.Option("-f|--framework <FRAMEWORK>", "Target framework to compile for", CommandOptionType.SingleValue); var runtime = app.Option("-r|--runtime <RUNTIME_IDENTIFIER>", "Target runtime to publish for", CommandOptionType.SingleValue); var buildBasePath = app.Option("-b|--build-base-path <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue); var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue); var versionSuffix = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines what `*` should be replaced with in version field in project.json", CommandOptionType.SingleValue); var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue); var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory"); var nativeSubdirectories = app.Option("--native-subdirectory", "Temporary mechanism to include subdirectories from native assets of dependency packages in output", CommandOptionType.NoValue); var noBuild = app.Option("--no-build", "Do not build projects before publishing", CommandOptionType.NoValue); app.OnExecute(() => { var publish = new PublishCommand(); publish.Framework = framework.Value(); publish.Runtime = runtime.Value(); publish.BuildBasePath = buildBasePath.Value(); publish.OutputPath = output.Value(); publish.Configuration = configuration.Value() ?? Constants.DefaultConfiguration; publish.NativeSubdirectories = nativeSubdirectories.HasValue(); publish.ProjectPath = projectPath.Value; publish.VersionSuffix = versionSuffix.Value(); publish.ShouldBuild = !noBuild.HasValue(); if (string.IsNullOrEmpty(publish.ProjectPath)) { publish.ProjectPath = Directory.GetCurrentDirectory(); } if (!publish.TryPrepareForPublish()) { return(1); } publish.PublishAllProjects(); Reporter.Output.WriteLine($"Published {publish.NumberOfPublishedProjects}/{publish.NumberOfProjects} projects successfully"); return((publish.NumberOfPublishedProjects == publish.NumberOfProjects) ? 0 : 1); }); try { return(app.Execute(args)); } catch (Exception ex) { Reporter.Error.WriteLine(ex.Message.Red()); Reporter.Verbose.WriteLine(ex.ToString().Yellow()); return(1); } }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "dotnet publish"; app.FullName = LocalizableStrings.AppFullName; app.Description = LocalizableStrings.AppDescription; app.HandleRemainingArguments = true; app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.HelpOption("-h|--help"); CommandArgument projectArgument = app.Argument($"<{LocalizableStrings.ProjectArgument}>", LocalizableStrings.ProjectArgDescription); CommandOption frameworkOption = app.Option( $"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription, CommandOptionType.SingleValue); CommandOption runtimeOption = app.Option( $"-r|--runtime <{LocalizableStrings.RuntimeOption}>", LocalizableStrings.RuntimeOptionDescription, CommandOptionType.SingleValue); CommandOption outputOption = app.Option( $"-o|--output <{LocalizableStrings.OutputOption}>", LocalizableStrings.OutputOptionDescription, CommandOptionType.SingleValue); CommandOption configurationOption = app.Option( $"-c|--configuration <{LocalizableStrings.ConfigurationOption}>", LocalizableStrings.ConfigurationOptionDescription, CommandOptionType.SingleValue); CommandOption versionSuffixOption = app.Option( $"--version-suffix <{LocalizableStrings.VersionSuffixOption}>", LocalizableStrings.VersionSuffixOptionDescription, CommandOptionType.SingleValue); CommandOption filterProjOption = app.Option( $"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription, CommandOptionType.SingleValue); CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); app.OnExecute(() => { var publish = new PublishCommand(); publish.ProjectPath = projectArgument.Value; publish.Framework = frameworkOption.Value(); publish.Runtime = runtimeOption.Value(); publish.OutputPath = outputOption.Value(); publish.Configuration = configurationOption.Value(); publish.VersionSuffix = versionSuffixOption.Value(); publish.FilterProject = filterProjOption.Value(); publish.Verbosity = verbosityOption.Value(); publish.ExtraMSBuildArguments = app.RemainingArguments; return(publish.Execute()); }); return(app.Execute(args)); }