Skip to content

Commit 2dfdf4b

Browse files
CopilotBillWagner
andcommitted
Update DebugType documentation to clarify default behavior and show how to disable PDB generation for Release builds
Co-authored-by: BillWagner <[email protected]>
1 parent dc27ed8 commit 2dfdf4b

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,14 +24,35 @@ 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>
3131
```
3232

3333
For all compiler versions starting with C# 6.0, there is no difference between *pdbonly* and *full*. Choose *pdbonly*. To change the location of the *.pdb* file, see [**PdbFile**](./advanced.md#pdbfile).
3434

35+
### Disabling PDB generation for Release builds
36+
37+
To suppress PDB file generation for Release builds while keeping them for Debug builds, add the following to your project file:
38+
39+
```xml
40+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
41+
<DebugType>none</DebugType>
42+
</PropertyGroup>
43+
```
44+
45+
Alternatively, you can set `DebugSymbols` to `false` for Release builds:
46+
47+
```xml
48+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
49+
<DebugSymbols>false</DebugSymbols>
50+
</PropertyGroup>
51+
```
52+
53+
> [!NOTE]
54+
> 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, for the most reliable way to disable PDB generation, explicitly set `DebugType` to `none`.
55+
3556
The following values are valid:
3657

3758
| Value | Meaning |
@@ -40,6 +61,7 @@ The following values are valid:
4061
| `pdbonly` | Same as `full`. See the note below for more information. |
4162
| `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. |
4263
| `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. |
64+
| `none` | Don't produce a PDB file. |
4365

4466
> [!IMPORTANT]
4567
> The following information applies only to compilers older than C# 6.0.

0 commit comments

Comments
 (0)