作法:檢視、儲存及設定組建記錄檔How to: View, save, and configure build log files

在 Visual Studio IDE 中建置專案之後,您可以在 [輸出] 視窗中檢視該組建的資訊。After you build a project in the Visual Studio IDE, you can view information about that build in the Output window. 例如,使用這項資訊,您可以針對建置失敗進行疑難排解。By using this information, you can, for example, troubleshoot a build failure.

  • 對於 C++ 專案,您也可以在自動建立和儲存的 .txt 檔案中,檢視相同的資訊。For C++ projects, you can also view the same information in a .txt file that's created and saved automatically.

  • 對於受控程式碼專案,您可以按一下建置輸出視窗,然後按 Ctrl+SFor managed code projects, you can click in the build output window and press Ctrl+S. Visual Studio 會提示您輸入位置,以將 [輸出] 視窗中的資訊儲存至 .txt 檔案。Visual Studio prompts you for a location to save the information from the Output window into a .txt file.

您也可以使用 IDE 來指定您想要檢視每個組建的資訊種類。You can also use the IDE to specify what kinds of information you want to view about each build.

如果您使用 MSBuild 建置任何種類的專案,您可以建立 .txt 檔案以儲存組建資訊。If you build any kind of project by using MSBuild, you can create a .txt file to save information about the build. 如需詳細資訊,請參閱取得組建記錄檔For more information, see Obtain build logs.

檢視 C++ 專案的組建記錄檔To view the build log file for a C++ project

  1. Windows 檔案總管檔案總管中,開啟下列檔案: \...\Visual Studio <版本>\Projects\<專案名稱>\<專案名稱>\Debug\<專案名稱>.txtIn Windows Explorer or File Explorer, open the following file: \...\Visual Studio <Version>\Projects\<ProjectName>\<ProjectName>\Debug\<ProjectName>.txt

建立受控碼專案的組建記錄檔To create a build log file for a managed-code project

  1. 在功能表列上選擇 [建置] > [建置解決方案] 。On the menu bar, choose Build > Build Solution.

  2. 在 [輸出] 視窗中,按一下文字中的某處。In the Output window, click somewhere in the text.

  3. Ctrl+SPress Ctrl+S.

    Visual Studio 會提示您輸入要儲存建置輸出的位置。Visual Studio prompts you for a location to save the build output.

您也可以透過直接從命令列執行 MSBuild (使用 -fileLogger (-fl) 命令列選項) 來產生記錄。You can also generate logs by running MSBuild directly from the command line, using the -fileLogger (-fl) command-line option. 請參閱使用 MSBuild 取得組建記錄檔See Obtain build logs with MSBuild.

變更組建記錄檔中包含的資訊量To change the amount of information included in the build log

  1. 在功能表列上選擇 [工具] > [選項] 。On the menu bar, choose Tools > Options.

  2. 在 [專案和解決方案] 頁面上,選擇 [建置並執行] 頁面。On the Projects and Solutions page, choose the Build and Run page.

  3. 在 [MSBuild 專案建置輸出詳細資訊層級] 清單中,選擇下列其中一個值,然後選擇 [確定] 按鈕。In the MSBuild project build output verbosity list, choose one of the following values, and then choose the OK button.

    詳細資訊層級Verbosity level 說明Description
    無訊息Quiet 只顯示組建摘要。Displays a summary of the build only.
    最少Minimal 顯示組建的摘要,及已分類為高重要性的錯誤、警告和訊息。Displays a summary of the build and errors, warnings, and messages that are categorized as highly important.
    正常Normal 顯示組建的摘要,及已分類為高重要性的錯誤、警告和訊息,還有組建的主要步驟。Displays a summary of the build; errors, warnings, and messages that are categorized as highly important; and the main steps of the build. 您將最常使用此詳細層級。You'll use this level of detail most frequently.
    詳細Detailed 顯示組建的摘要,及已分類為高重要性的錯誤、警告和訊息,組建的所有步驟,以及分類為正常重要性的訊息。Displays a summary of the build; errors, warnings, and messages that are categorized as highly important; all of the steps of the build; and messages that are categorized as of normal importance.
    診斷Diagnostic 顯示組建可用的所有資料。Displays all data that's available for the build. 您可以使用此詳細層級以協助偵錯自訂建置指令碼的問題和其他組建問題。You can use this level of detail to help debug issues with custom build scripts and other build issues.

    如需詳細資訊,請參閱選項對話方塊、專案和解決方案、建置並執行LoggerVerbosityFor more information, see Options dialog box, Projects and Solutions, Build and Run and LoggerVerbosity.

    Important

    您必須重建專案,您的變更才會在 [輸出] 視窗 (所有專案) 和 <專案名稱>.txt 檔案 (僅限 C++ 專案) 中生效。You must rebuild the project for your changes to take effect in the Output window (all projects) and the <ProjectName>.txt file (C++ projects only).

使用二進位記錄檔來輕鬆瀏覽大型記錄檔Use binary logs to make it easier to browse large log files

二進位記錄檔是適用於 .NET 專案的選擇性功能,它可讓您擁有更豐富的記錄檔瀏覽體驗,以便您可以輕鬆地在大型記錄中尋找資訊。Binary logs are an optional feature for .NET projects that lets you have a richer log browsing experience that might make it easier to find information in large logs. 若要使用二進位記錄檔,請安裝 Project System ToolsTo use binary logs, install the Project System Tools. 如需詳細資訊,請參閱 https://msbuildlog.com 二進位記錄檔For more information, see https://msbuildlog.com and Binary Log

另請參閱See also