Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article applies to: ✔️ .NET 6 SDK and later versions
Name
dotnet clean - Cleans the output of a project.
Synopsis
dotnet clean [<PROJECT>|<SOLUTION>|<FILE>] [--artifacts-path <ARTIFACTS_DIR>]
[-c|--configuration <CONFIGURATION>]
[-f|--framework <FRAMEWORK>] [--interactive]
[--nologo] [-o|--output <OUTPUT_DIRECTORY>]
[-r|--runtime <RUNTIME_IDENTIFIER>] [--tl:[auto|on|off]]
[-v|--verbosity <LEVEL>]
dotnet clean -h|--help
Description
The dotnet clean command cleans the output of the previous build. It's implemented as an MSBuild target, so the project is evaluated when the command is run. Only the outputs created during the build are cleaned. Both intermediate (obj) and final output (bin) folders are cleaned.
Arguments
PROJECT | SOLUTION | FILE
The project or solution or C# (file-based app) file to operate on. If a file isn't specified, MSBuild searches the current directory for a project or solution.
PROJECTis the path and filename of a C#, F#, or Visual Basic project file, or the path to a directory that contains a C#, F#, or Visual Basic project file.SOLUTIONis the path and filename of a solution file (.sln or .slnx extension), or the path to a directory that contains a solution file.FILEis an argument added in .NET 10. The path and filename of a file-based app. File-based apps are contained within a single file that is built and run without a corresponding project (.csproj) file. For more information, see Build file-based C# apps.
Options
--artifacts-path <ARTIFACTS_DIR>All build output files from the executed command will go in subfolders under the specified path, separated by project. For more information see Artifacts Output Layout. Available since .NET 8 SDK.
-c|--configuration <CONFIGURATION>Defines the build configuration. The default for most projects is
Debug, but you can override the build configuration settings in your project. This option is only required when cleaning if you specified it during build time.
-f|--framework <FRAMEWORK>The framework that was specified at build time. The framework must be defined in the project file. If you specified the framework at build time, you must specify the framework when cleaning.
-?|-h|--helpPrints out a description of how to use the command.
--interactiveAllows the command to stop and wait for user input or action. For example, to complete authentication. Available since .NET Core 3.0 SDK.
--nologoDoesn't display the startup banner or the copyright message.
-o|--output <OUTPUT_DIRECTORY>The directory that contains the build artifacts to clean. Specify the
-f|--framework <FRAMEWORK>switch with the output directory switch if you specified the framework when the project was built..NET 7.0.200 SDK and later
If you specify the
--outputoption when running this command on a solution, the CLI will emit a warning (an error in 7.0.200) due to the unclear semantics of the output path. The--outputoption is disallowed because all outputs of all built projects would be copied into the specified directory, which isn't compatible with multi-targeted projects, as well as projects that have different versions of direct and transitive dependencies. For more information, see Solution-level--outputoption no longer valid for build-related commands.
-r|--runtime <RUNTIME_IDENTIFIER>Cleans the output folder of the specified runtime. This is used when a self-contained deployment was created.
--tl:[auto|on|off]Specifies whether Terminal Logger should be used for the build output. The default is
auto, which first verifies the environment before enabling terminal logging. The environment check verifies that the terminal is capable of using modern output features and isn't using a redirected standard output before enabling the new logger.onskips the environment check and enables terminal logging.offskips the environment check and uses the default console logger.Terminal Logger shows you the restore phase followed by the build phase. During each phase, the currently building projects appear at the bottom of the terminal. Each project that's building outputs both the MSBuild target currently being built and the amount of time spent on that target. You can search this information to learn more about the build. When a project is finished building, a single "build completed" section is written that captures:
- The name of the built project.
- The target framework (if multi-targeted).
- The status of that build.
- The primary output of that build (which is hyperlinked).
- Any diagnostics generated for that project.
This option is available starting in .NET 8.
-v|--verbosity <LEVEL>Sets the verbosity level of the command. Allowed values are
q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]. The default isnormal. For more information, see LoggerVerbosity.
Examples
Clean a default build of the project:
dotnet cleanClean a file-based program:
dotnet clean Program.cs.File-based app support was added in .NET SDK 10.0.100.
Clean a project built using the Release configuration:
dotnet clean --configuration Release