// 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. using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; namespace Microsoft.DotNet.Tools.Clean { public class CleanCommand { public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false) { Name = "dotnet clean", FullName = ".NET Clean Command", Description = "Command to clean previously generated build outputs.", AllowArgumentSeparator = true, ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText }; app.HelpOption("-h|--help"); CommandArgument projectArgument = app.Argument("", "The MSBuild project file to build. If a project file is not specified," + " MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."); CommandOption outputOption = app.Option("-o|--output ", "Directory in which the build outputs have been placed", CommandOptionType.SingleValue); CommandOption frameworkOption = app.Option("-f|--framework ", "Clean a specific framework", CommandOptionType.SingleValue); CommandOption configurationOption = app.Option("-c|--configuration ", "Clean a specific configuration", CommandOptionType.SingleValue); CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); app.OnExecute(() => { List msbuildArgs = new List(); if (!string.IsNullOrEmpty(projectArgument.Value)) { msbuildArgs.Add(projectArgument.Value); } msbuildArgs.Add("/t:Clean"); if (outputOption.HasValue()) { msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}"); } if (frameworkOption.HasValue()) { msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); } if (configurationOption.HasValue()) { msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); } if (verbosityOption.HasValue()) { msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); } msbuildArgs.AddRange(app.RemainingArguments); return new MSBuildForwardingApp(msbuildArgs).Execute(); }); return app.Execute(args); } } }