From c32bd4b52283ea3f6eeaf19457d8b21847f20b0e Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 28 Jun 2025 15:18:00 +0800 Subject: [PATCH] Enhance `CleanCommand` to run 'dotnet clean' . Resolve #23184 --- .../Volo/Abp/Cli/Commands/CleanCommand.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanCommand.cs index 71964653a7..092e996095 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanCommand.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands; @@ -13,11 +14,14 @@ namespace Volo.Abp.Cli.Commands; public class CleanCommand : IConsoleCommand, ITransientDependency { public const string Name = "clean"; - + public ILogger Logger { get; set; } - public CleanCommand() + protected ICmdHelper CmdHelper { get; } + + public CleanCommand(ICmdHelper cmdHelper) { + CmdHelper = cmdHelper; Logger = NullLogger.Instance; } @@ -26,6 +30,10 @@ public class CleanCommand : IConsoleCommand, ITransientDependency var binEntries = Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "bin", SearchOption.AllDirectories); var objEntries = Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "obj", SearchOption.AllDirectories); + Logger.LogInformation("Cleaning the solution with 'dotnet clean' command..."); + CmdHelper.RunCmd($"dotnet clean", workingDirectory: Directory.GetCurrentDirectory()); + + Logger.LogInformation($"Removing 'bin' and 'obj' folders..."); foreach (var path in binEntries.Concat(objEntries)) { if (path.IndexOf("node_modules", StringComparison.OrdinalIgnoreCase) > 0) @@ -38,9 +46,9 @@ public class CleanCommand : IConsoleCommand, ITransientDependency Directory.Delete(path, true); } } + Logger.LogInformation($"'bin' and 'obj' folders removed successfully!"); - Logger.LogInformation($"BIN and OBJ folders have been successfully deleted!"); - + Logger.LogInformation("Solution cleaned successfully!"); return Task.CompletedTask; }