在 Visual Studio 中設定偵錯和發行組態Set debug and release configurations in Visual Studio

Visual Studio 專案針對您的程式具有不同的版本和偵錯組態。Visual Studio projects have separate release and debug configurations for your program. 您會建立用於偵錯工具的 debug 版本, 以及最終發行散發的發行版本。You build the debug version for debugging and the release version for the final release distribution.

在 [偵測設定] 中, 您的程式會使用完整符號的 debug 資訊進行編譯, 而且不會優化。In debug configuration, your program compiles with full symbolic debug information and no optimization. 最佳化會使偵錯變得複雜,因為原始程式碼與產生的指令之間關係較為複雜。Optimization complicates debugging, because the relationship between source code and generated instructions is more complex.

程式的發行設定沒有符號的 debug 資訊, 而且已完全優化。The release configuration of your program has no symbolic debug information and is fully optimized. 針對 managed 程式碼C++和程式碼, 可以根據所使用的編譯器選項, 在 .pdb 檔案中產生 debug 資訊。For managed code and C++ code, debug information can be generated in .pdb files, depending on the compiler options that are used. 如果您稍後需要對發行版本進行偵錯工具, 建立 .pdb 檔案可能會很有用。Creating .pdb files can be useful if you later have to debug your release version.

如需組建組態的詳細資訊,請參閱了解組建組態For more information about build configurations, see Understand build configurations.

您可以從 [建置] 功能表、從工具列,或在專案的屬性頁中變更組建組態。You can change the build configuration from the Build menu, from the toolbar, or in the project's property pages. 專案屬性頁因語言而異。Project property pages are language-specific. 下列程序示範如何從功能表和工具列變更組建組態。The procedure below shows how to change the build configuration from the menu and the toolbar. 如需如何在不同語言的專案中變更組建設定的詳細資訊, 請參閱下面的另請參閱一節。For more information about how to change the build configuration in projects in different languages, see the See also section below.

變更組建設定Change the build configuration

若要變更組建設定, 請執行下列其中一項:To change the build configuration, either:

  • 從 [建立] 功能表中, 選取 [ Configuration Manager], 然後選取 [ Debug ] 或 [ Release]。From the Build menu, select Configuration Manager, then select Debug or Release.

or

  • 在工具列的 [解決方案組態] 清單中,選擇 [偵錯] 或 [發行]。On the toolbar, choose either Debug or Release from the Solution Configurations list.

    工具列組建 設定toolbars build configuration

產生組建的符號 (.pdb) 檔 (C#、 C++、Visual Basic、) F#Generate symbol (.pdb) files for a build (C#, C++, Visual Basic, F#)

您可以選擇產生符號 (.pdb) 檔, 以及要包含哪些 debug 資訊。You can choose to generate symbol (.pdb) files and what debug information to include. 對於大部分的專案類型, 編譯器預設會針對 debug 和 release 組建產生符號檔, 而其他預設設定會因專案類型和 Visual Studio 版本而有所不同。For most project types, the compiler generates symbol files by default for debug and release builds, while other default settings differ by project type and Visual Studio version.

Important

偵錯工具只會載入與可執行檔建置時所建立的 .pdb 檔案完全相同之可執行檔的 .pdb 檔案 (也就是說,.pdb 必須是原始 .pdb 檔案或該檔案的複本)。The debugger will load only a .pdb file for an executable file that exactly matches the .pdb file that was created when the executable was built (that is, the .pdb must be the original or a copy of the original .pdb file). 如需詳細資訊, 請參閱為什麼 Visual Studio 需要偵錯工具符號檔完全符合用來建立它們的二進位檔案?For more information, see Why does Visual Studio require debugger symbol files to exactly match the binary files that they were built with?.

每個專案類型可能會有不同的方式來設定這些選項。Each project type may have a different way of setting these options.

產生C#、ASP.NET 或 Visual Basic 專案的符號檔Generate symbol files for a C#, ASP.NET, or Visual Basic project

如需或 Visual Basic 中C#的 debug 設定之專案設定的詳細資訊, 請參閱 Visual Basic debug 設定之 [ C#調試程式] 或 [專案設定] 的專案設定。For detailed information on project settings for debug configurations in C# or Visual Basic, see Project settings for a C# debug configuration or Project settings for a Visual Basic debug configuration.

  1. 在 [方案總管] 中選取專案。In Solution Explorer, select the project.

  2. 選取 [屬性] 圖示 (或按Alt + Enter)。Select the Properties icon (or press Alt+Enter).

  3. 在側邊窗格中, 選擇 [組建] (或 [在 Visual Basic 中編譯])。In the side pane, choose Build (or Compile in Visual Basic).

  4. 在 [設定] 清單中, 選擇 [ Debug ] 或 [ Release]。In the Configuration list, choose Debug or Release.

  5. 選取 [ advanced ] 按鈕 (或 Visual Basic 中的 [高級編譯選項] 按鈕)。Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

  6. 在 [調試資訊] 清單中 (或 Visual Basic 中的 [產生調試資訊] 清單), 選擇 [完整]、[僅限 Pdb] 或 [可移植]。In the Debugging information list (or the Generate debug info list in Visual Basic), choose Full, Pdb-only, or Portable.

    可移植格式是適用于 .NET Core 的最新跨平臺格式。The portable format is the most recent cross-platform format for .NET Core. 如需選項的詳細資訊, 請參閱Advanced Build Settings dialogC#box ()For more information on options, see Advanced Build Settings dialog box (C#).

    在中C#產生組建的 pdbGenerate PDBs for builds in C#

  7. 建置您的專案。Build your project.

    編譯器會在可執行檔或主要輸出檔所在的相同資料夾中建立符號檔。The compiler creates the symbol file(s) in the same folder as the executable or the main output file.

產生C++專案的符號檔Generate symbol files for a C++ project

  1. 在 [方案總管] 中選取專案。In Solution Explorer, select the project.

  2. 選取 [屬性] 圖示 (或按Alt + Enter)。Select the Properties icon (or press Alt+Enter).

  3. 在 [設定] 清單中, 選擇 [ Debug ] 或 [ Release]。In the Configuration list, choose Debug or Release.

  4. 在側邊窗格中, 選擇 [連結器] > [調試程式], 然後選取 [產生 Debug 資訊的選項]。In the side pane, choose Linker > Debugging, then select options for Generate Debug Info.

    如需中C++的偵錯工具設定的詳細資訊, 請參閱用於C++偵錯工具的專案設定For detailed information on project settings for debug configurations in C++, see Project settings for a C++ debug configuration.

  5. 設定產生程式資料庫檔案的選項。Configure options for Generate Program Database Files.

    在大部分C++的專案中, 預設值$(OutDir)$(TargetName).pdb是, 它會在輸出檔案夾中產生 .pdb 檔案。In most C++ projects, the default value is $(OutDir)$(TargetName).pdb, which generates .pdb files in the output folder.

    在中C++產生組建的 pdbGenerate PDBs for builds in C++

  6. 建置您的專案。Build your project.

    編譯器會在可執行檔或主要輸出檔所在的相同資料夾中建立符號檔。The compiler creates the symbol file(s) in the same folder as the executable or the main output file.

另請參閱See also