Include pdb files into my nuget (nupkg) files
If you are using VS2017 15.4 or later, you can define a MSBuild property in your project file
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
This is discussed in NuGet #4142
However, there is still an issue as the new project system does not copy the pdbs from packages to the bin/publish folder for .NET Core 3.0+, a good summary is also at sourcelink/#628
Currently this is not planned to be fixed until .NET 7 :-(
In the meantime a work-around is to include the following fragment into API and test projects to ensure you have the appropriate pdbs to allow you to step into the remote source code.
<!-- https://github.com/dotnet/sdk/issues/1458#issuecomment-1063915490 -->
<Target Name="IncludeSymbolFiles" AfterTargets="ResolveAssemblyReferences" Condition="@(ReferenceCopyLocalPaths) != ''">
<ItemGroup>
<ReferenceCopyLocalPaths Include="%(ReferenceCopyLocalPaths.RelativeDir)%(ReferenceCopyLocalPaths.Filename).pdb; %(ReferenceCopyLocalPaths.RelativeDir)%(ReferenceCopyLocalPaths.Filename).xml" />
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" Condition="!Exists('%(FullPath)')" />
</ItemGroup>
</Target>
While it may not help for debugging, it's definitely useful to include .pdb files so that stack traces have line numbers.
In the nuspec file, include a <files>
element (child of <package>
, sibling of <metadata>
). This is what I have in one of my class libraries:
<files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net452\" />
</files>
Make sure the target is the same folder as where your .dll file is put in the package.