Include pdb files into my nuget (nupkg) files

2020-02-23 04:49发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

With the new csproj format NuGet creation is pretty easier, since MSBuild does most of the work.

In order to include your pdb files you just have to enter the tag

<IncludeSymbols>true</IncludeSymbols>

in a property group in the csproj file of the project you are packing. This will create an additional .symbols.nupkg package, which you can release to your (debug) feed.



回答4:

Refer to this link. Actually you should add -Symbols to the end of command to create a symbols package. You shouldn't add pdb files to main nuget package.



回答5:

Enable Symbol and Source Server

When set, ProGet will scan NuGet packages for .pdb files and make them available as a symbol server at the /symbols/[FeedName] URL. See the Symbol Server section for additional information.

From: inedo.com