dotnet cleandotnet clean

本文适用于: ✔️ .NET Core 2.x SDK 及更高版本This article applies to: ✔️ .NET Core 2.x SDK and later versions

名称Name

dotnet clean - 清除项目输出。dotnet clean - Cleans the output of a project.

摘要Synopsis

dotnet clean [<PROJECT>|<SOLUTION>] [-c|--configuration <CONFIGURATION>]
    [-f|--framework <FRAMEWORK>] [--interactive]
    [--nologo] [-o|--output <OUTPUT_DIRECTORY>]
    [-r|--runtime <RUNTIME_IDENTIFIER>] [-v|--verbosity <LEVEL>]

dotnet clean -h|--help

说明Description

dotnet clean 命令可清除上一个生成的输出。The dotnet clean command cleans the output of the previous build. 它以 MSBuild 目标 的形式实现,以便在运行命令时对项目进行评估。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. 中间 (obj) 和最终输出 (bin) 文件夹都会被清除。Both intermediate (obj) and final output (bin) folders are cleaned.

参数Arguments

PROJECT | SOLUTION

要清理的 MSBuild 项目或解决方案。The MSBuild project or solution to clean. 如果未指定项目或解决方案文件,MSBuild 会在当前工作目录中搜索文件扩展名以 projsln 结尾的文件并使用该文件。If a project or solution file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in proj or sln, and uses that file.

选项Options

  • -c|--configuration <CONFIGURATION>

    定义生成配置。Defines the build configuration. 大多数项目的默认配置为 Debug,但你可以覆盖项目中的生成配置设置。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|--help

    打印出有关命令的简短帮助。Prints out a short help for the command.

  • --interactive

    允许命令停止并等待用户输入或操作。Allows the command to stop and wait for user input or action. 例如,完成身份验证。For example, to complete authentication. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

  • --nologo

    不显示启动版权标志或版权消息。Doesn't display the startup banner or the copyright message. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

  • -o|--output <OUTPUT_DIRECTORY>

    包含要清理的生成项目的目录。The directory that contains the build artifacts to clean. 如果在生成项目时指定了框架,则使用输出目录开关指定 -f|--framework <FRAMEWORK> 开关。Specify the -f|--framework <FRAMEWORK> switch with the output directory switch if you specified the framework when the project was built.

  • -r|--runtime <RUNTIME_IDENTIFIER>

    清除指定运行时的输出文件夹。Cleans the output folder of the specified runtime. 在创建独立部署 (SCD) 时使用此选项。This is used when a self-contained deployment was created.

  • -v|--verbosity <LEVEL>

    设置 MSBuild 详细级别。Sets the MSBuild verbosity level. 允许使用的值为 q[uiet]m[inimal]n[ormal]d[etailed]diag[nostic]Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. 默认值为 normalThe default is normal.

示例Examples

  • 清除项目的默认生成:Clean a default build of the project:

    dotnet clean
    
  • 清除使用版本配置生成的项目:Clean a project built using the Release configuration:

    dotnet clean --configuration Release