dotnet publish CLI exclude .pdb

Viewed 1040

In .NET 7, I do:

dotnet publish --self-contained --configuration Release --runtime win7-x64 --output myapp

How do I prevent .pdb files in the result? Ideally, just using the CLI?

Are there any additional steps I can take to decrease the result size?

2 Answers

According to this GitHub issue, there are two ways you can disable symbols.

You can either edit the .csproj file to add these two entries:

<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>

Or you can pass the following as part of the dotnet publish command:

/p:DebugType=None /p:DebugSymbols=false

For example:

dotnet publish /p:DebugType=None /p:DebugSymbols=false --self-contained --configuration Release --runtime win7-x64 --output myapp

To disable .pdb files only for release, add this to your Project.csproj:

<PropertyGroup Condition="'$(Configuration)'=='Release'">
  <DebugSymbols>False</DebugSymbols>
  <DebugType>None</DebugType>
</PropertyGroup>
Related