Skip to content

Commit e6878f7

Browse files
CopilotBillWagnergewarren
authored
Update DebugType documentation to clarify default behavior and show how to disable PDB generation for Release builds (#47376)
* Initial plan * Update DebugType documentation to clarify default behavior and show how to disable PDB generation for Release builds Co-authored-by: BillWagner <[email protected]> * Move PDB disabling section after values table and improve wording Co-authored-by: gewarren <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: gewarren <[email protected]>
1 parent 712b62c commit e6878f7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

docs/csharp/language-reference/compiler-options/code-generation.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The following options control code generation by the compiler. The new MSBuild s
2424
2525
## DebugType
2626

27-
The **DebugType** option causes the compiler to generate debugging information and place it in the output file or files. Debugging information is added by default.
27+
The **DebugType** option causes the compiler to generate debugging information and place it in the output file or files. The default value is `portable` for both Debug and Release build configurations, which means PDB files are generated by default for all configurations.
2828

2929
```xml
3030
<DebugType>pdbonly</DebugType>
@@ -40,11 +40,33 @@ The following values are valid:
4040
| `pdbonly` | Same as `full`. See the note below for more information. |
4141
| `portable` | Emit debugging information to .pdb file using cross-platform [Portable PDB](https://github.com/dotnet/designs/blob/main/accepted/2020/diagnostics/portable-pdb.md) format. |
4242
| `embedded` | Emit debugging information into the _.dll/.exe_ itself (_.pdb_ file is not produced) using [Portable PDB](https://github.com/dotnet/designs/blob/main/accepted/2020/diagnostics/portable-pdb.md) format. |
43+
| `none` | Don't produce a PDB file. |
4344

4445
> [!IMPORTANT]
4546
> The following information applies only to compilers older than C# 6.0.
4647
> The value of this element can be either `full` or `pdbonly`. The *full* argument, which is in effect if you don't specify *pdbonly*, enables attaching a debugger to the running program. Specifying *pdbonly* allows source code debugging when the program is started in the debugger but will only display assembler when the running program is attached to the debugger. Use this option to create debug builds. If you use *Full*, be aware that there's some impact on the speed and size of JIT optimized code and a small impact on code quality with *full*. We recommend *pdbonly* or no PDB for generating release code. One difference between *pdbonly* and *full* is that with *full* the compiler emits a <xref:System.Diagnostics.DebuggableAttribute>, which is used to tell the JIT compiler that debug information is available. Therefore, you will get an error if your code contains the <xref:System.Diagnostics.DebuggableAttribute> set to false if you use *full*. For more information on how to configure the debug performance of an application, see [Making an Image Easier to Debug](../../../framework/debug-trace-profile/making-an-image-easier-to-debug.md).
4748
49+
### Disable PDB generation for Release builds
50+
51+
To suppress PDB file generation for Release builds while keeping them for Debug builds, add the following property to your project file:
52+
53+
```xml
54+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
55+
<DebugType>none</DebugType>
56+
</PropertyGroup>
57+
```
58+
59+
Alternatively, you can set `DebugSymbols` to `false` for Release builds:
60+
61+
```xml
62+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
63+
<DebugSymbols>false</DebugSymbols>
64+
</PropertyGroup>
65+
```
66+
67+
> [!NOTE]
68+
> In .NET 8 and later versions, setting `DebugSymbols` to `false` should suppress PDB generation according to the [breaking change documentation](../../../core/compatibility/sdk/8.0/debugsymbols.md). However, the most reliable way to disable PDB generation is to explicitly set `DebugType` to `none`.
69+
4870
## Optimize
4971

5072
The **Optimize** option enables or disables optimizations performed by the compiler to make your output file smaller, faster, and more efficient. The *Optimize* option is enabled by default for a *Release* build configuration. It is off by default for a *Debug* and any other build configuration.

0 commit comments

Comments
 (0)