12

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?

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
kofifus
  • 17,260
  • 17
  • 99
  • 173
  • https://github.com/dotnet/sdk/issues/16975#issuecomment-597612660 – stuartd Mar 15 '22 at 02:27
  • @LeiYang [The successor to .NET 6?](https://devblogs.microsoft.com/dotnet/announcing-net-7-preview-1/) – ProgrammingLlama Mar 15 '22 at 02:37
  • sorry, i'm not aware of it. is .net advancing so fast? – Lei Yang Mar 15 '22 at 02:38
  • 1
    @LeiYang .NET 6 was released Nov 2021, .NET 5 was released Nov 2020, .NET Core 3.1 was released Dec 2019. It seems to be once a year. A prerelease in 2022 for .NET 7 seems to fit well into that timeline. – ProgrammingLlama Mar 15 '22 at 02:39
  • Does this answer your question? [Disable generating PDB files in MsBuild](https://stackoverflow.com/questions/773796/disable-generating-pdb-files-in-msbuild) – gunr2171 Mar 15 '22 at 03:16
  • Note that if you are experiencing .pdb files **and loads of other junk files** in your publishing directory, you are probably suffering from [this issue][1] which is reported to Microsoft [here][2]. – Hugh W Jan 16 '23 at 12:05

2 Answers2

17

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
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
13

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

<PropertyGroup Condition="'$(Configuration)'=='Release'">
  <DebugSymbols>False</DebugSymbols>
  <DebugType>None</DebugType>
</PropertyGroup>
lonix
  • 14,255
  • 23
  • 85
  • 176