Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include pdb files into my nuget (nupkg) files

I am using MSBuild to generate my nuget packages.

Is there any command I need to set, to allow it to include my .pdb files, for stepping into the source while debugging?

I do not want the source files to be included into the project that is pulling in the nuget package.

like image 514
monstertjie_za Avatar asked Jan 18 '17 07:01

monstertjie_za


People also ask

Should I include PDB files in NuGet package?

You shouldn't add pdb files to main nuget package.

Where do I put PDB files?

pdb file stores all debug information for the project's .exe file, and resides in the \debug subdirectory. The <project>. pdb file contains full debug information, including function prototypes, not just the type information found in VC<x>. pdb.

How do I package a Nupkg?

You can configure Visual Studio to automatically generate the NuGet package when you build the project. In Solution Explorer, right-click the project and choose Properties. In the Package tab, select Generate NuGet package on build.


2 Answers

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 6 :-(

like image 84
Paul Hatcher Avatar answered Sep 16 '22 22:09

Paul Hatcher


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.

like image 30
Jeff Shepler Avatar answered Sep 17 '22 22:09

Jeff Shepler