.NET Core 2 Publish with Symbols
Akash Kava

Akash Kava @akashkava

About: Author of Web Atoms

Location:
India
Joined:
Jan 6, 2018

.NET Core 2 Publish with Symbols

Publish Date: Mar 12 '19
6 1

Missing pdb files

Default dotnet publish behaviour omits all pdb files, leaves you with puzzle of where the exception has occurred. I never liked omitting pdb on production, if one does not have source code, a line number would do what?

Hack

Really dirty hack, found after 2 hours of digging github issues.

Code

Edit your csproj file, and add following lines.

  <Target Name="_ResolvePublishNuGetPackagePdbsAndXml" AfterTargets="RunResolvePublishAssemblies">
    <ItemGroup>
      <ResolvedFileToPublish Include="@(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).pdb')" RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))" DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))" Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''&#xD;&#xA;                    and Exists('%(RootDir)%(Directory)%(Filename).pdb')" />
      <ResolvedFileToPublish Include="@(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).xml')" RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))" DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))" Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''&#xD;&#xA;                    and Exists('%(RootDir)%(Directory)%(Filename).xml')" />
    </ItemGroup>
  </Target>
Enter fullscreen mode Exit fullscreen mode

Warning

It is subjected to completely change in .net core 3. I will post an update here when it is shipped.

Comments 1 total

Add comment