dotnet publish CLI exclude .pdb
Asked Answered
P

2

18

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?

Prickett answered 15/3, 2022 at 2:23 Comment(6)
github.com/dotnet/sdk/issues/16975#issuecomment-597612660Anastassia
@LeiYang The successor to .NET 6?Gilburt
sorry, i'm not aware of it. is .net advancing so fast?Griffon
@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.Gilburt
Does this answer your question? Disable generating PDB files in MsBuildFlita
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].Owing
G
23

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
Gilburt answered 15/3, 2022 at 3:50 Comment(3)
I think, those properties are related to build, so they have no effect if you run dotnet publish --no-buildBreastplate
@Breastplate Yes, they are MSBuild options. You can also pass the same options to dotnet build I believe.Gilburt
When I try this and I but this two lines in my .pubxml file I get this error: #77071559Amaris
P
23

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

<PropertyGroup Condition="'$(Configuration)'=='Release'">
  <DebugSymbols>False</DebugSymbols>
  <DebugType>None</DebugType>
</PropertyGroup>
Presbyter answered 31/5, 2022 at 13:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.