public int Execute(OnExecute execute, string[] args) { _app.OnExecute(() => { if (_outputOption.HasValue() && !_frameworkOption.HasValue()) { Reporter.Error.WriteLine("When the '--output' option is provided, the '--framework' option must also be provided."); return(1); } OutputValue = _outputOption.Value(); BuildBasePathValue = PathUtility.GetFullPath(_buildBasePath.Value()); ConfigValue = _configurationOption.Value() ?? Constants.DefaultConfiguration; RuntimeValue = _runtimeOption.Value(); VersionSuffixValue = _versionSuffixOption.Value(); ShouldPrintIncrementalPreconditions = _shouldPrintIncrementalPreconditionsArgument.HasValue(); ShouldNotUseIncrementality = _shouldNotUseIncrementalityArgument.HasValue(); ShouldSkipDependencies = _shouldSkipDependenciesArgument.HasValue(); // Set defaults based on the environment if (Workspace == null) { Workspace = BuildWorkspace.Create(VersionSuffixValue); } var files = new ProjectGlobbingResolver().Resolve(_projectArgument.Values); IEnumerable <NuGetFramework> frameworks = null; if (_frameworkOption.HasValue()) { frameworks = new[] { NuGetFramework.Parse(_frameworkOption.Value()) }; } var success = execute(files, frameworks, this); return(success ? 0 : 1); }); return(_app.Execute(args)); }
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 = PathUtility.GetFullPath(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(); publish.Workspace = BuildWorkspace.Create(versionSuffix.Value()); 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 pack"; app.FullName = ".NET Packager"; app.Description = "Packager for the .NET Platform"; app.HelpOption("-h|--help"); var output = app.Option("-o|--output <OUTPUT_DIR>", "Directory in which to place outputs", CommandOptionType.SingleValue); var noBuild = app.Option("--no-build", "Do not build project before packing", CommandOptionType.NoValue); var buildBasePath = app.Option("-b|--build-base-path <OUTPUT_DIR>", "Directory in which to place temporary build outputs", CommandOptionType.SingleValue); var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", 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 serviceable = app.Option("-s|--serviceable", "Set the serviceable flag in the package", CommandOptionType.NoValue); var path = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory"); app.OnExecute(() => { // Locate the project and get the name and full path var pathValue = path.Value; if (string.IsNullOrEmpty(pathValue)) { pathValue = Directory.GetCurrentDirectory(); } if (!pathValue.EndsWith(Project.FileName)) { pathValue = Path.Combine(pathValue, Project.FileName); } if (!File.Exists(pathValue)) { Reporter.Error.WriteLine($"Unable to find a project.json in {pathValue}"); return(1); } // Set defaults based on the environment var workspace = BuildWorkspace.Create(versionSuffix.Value()); var configValue = configuration.Value() ?? Cli.Utils.Constants.DefaultConfiguration; var outputValue = output.Value(); var buildBasePathValue = PathUtility.GetFullPath(buildBasePath.Value()); var contexts = workspace.GetProjectContextCollection(pathValue).FrameworkOnlyContexts; var project = contexts.First().ProjectFile; var artifactPathsCalculator = new ArtifactPathsCalculator(project, buildBasePathValue, outputValue, configValue); var packageBuilder = new PackagesGenerator(contexts, artifactPathsCalculator, configValue); project.Serviceable = serviceable.HasValue(); int buildResult = 0; if (!noBuild.HasValue()) { var buildProjectCommand = new BuildProjectCommand(project, buildBasePathValue, configValue, workspace); buildResult = buildProjectCommand.Execute(); } return(buildResult != 0 ? buildResult : packageBuilder.Build()); }); try { return(app.Execute(args)); } catch (Exception ex) { #if DEBUG Console.Error.WriteLine(ex); #else Console.Error.WriteLine(ex.Message); #endif return(1); } }