dotnet cleandotnet clean

本主題適用於:✓ .NET Core 1.x SDK 和更新版本This topic applies to: ✓ .NET Core 1.x SDK and later versions


dotnet clean - 清除專案的輸出。dotnet clean - Cleans the output of a project.


dotnet clean [<PROJECT>|<SOLUTION>] [-c|--configuration] [-f|--framework] [--interactive] 
    [--nologo] [-o|--output] [-r|--runtime] [-v|--verbosity]
dotnet clean [-h|--help]


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.



要清除的 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.


  • -c|--configuration {Debug|Release}

    定義組建組態。Defines the build configuration. 預設值為 DebugThe default value is Debug. 如果在建置階段指定此選項,清除時才需要使用它。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. 自 .NET Core 2.0 SDK 起可用的選項。Option available since .NET Core 2.0 SDK.

  • -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.


  • 清除專案的預設組建︰Clean a default build of the project:

    dotnet clean
  • 清除使用發行組態來建置的專案︰Clean a project built using the Release configuration:

    dotnet clean --configuration Release