Consumıng Symbol Packages¶
Ensure .pdb files are included in the NuGet Package¶
When creating your NuGet package, make sure the .pdb
files are included. You can do this by adding the following to your .csproj
file:
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
This ensures that the .pdb
files are included in the .snupkg
symbol package when you run dotnet pack
.
Extract .pdb files from NuGet Packages¶
To automatically extract .pdb
files from NuGet packages during the build process, you can use MSBuild targets. Add the following to your .csproj
file:
<Target Name="_ResolveCopyLocalNuGetPackagePdbs" Condition="$(CopyLocalLockFileAssemblies) == true" AfterTargets="ResolveReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->'%(RootDir)%(Directory)%(Filename).pdb')" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' != '' and Exists('%(RootDir)%(Directory)%(Filename).pdb')" />
</ItemGroup>
</Target>
How It Works:
-
Condition: The target runs only if
$(CopyLocalLockFileAssemblies)
istrue
, which means it will only execute when the project is copying local dependencies (e.g., for executables or self-contained deployments). -
Item Group: It iterates over the
ReferenceCopyLocalPaths
items (which represent the assemblies being copied to the output directory) and attempts to include the corresponding.pdb
files. -
Condition: It checks if the
.pdb
file exists and if the assembly comes from a NuGet package(%(ReferenceCopyLocalPaths.NuGetPackageId)
is not empty).
Ensure .pdb files are not excluded¶
Visual Studio may skip loading .pdb
files if they are excluded or marked as "just my code." To check:
-
Go to Tools > Options.
-
Navigate to Debugging > General.
-
Ensure the following settings are configured:
-
Enable Just My Code: Unchecked.
-
Enable .NET Framework Source Stepping: Unchecked.
-
Enable Source Server Support: Checked.
-
Enable Source Link Support: Checked.
-
Ensure .pdb files are loaded during debugging¶
Visual Studio automatically loads .pdb
files from the output directory ($(OutputPath))
when debugging. By copying the .pdb
files to the output directory (as shown above), they will be available for the debugger.
-
Start debugging your application
(F5)
. -
Open the Modules window (Debug > Windows > Modules).
-
Look for the assemblies you are debugging. If the
.pdb
files are loaded correctly, you should seeSymbols loaded
in theSymbol Status
column.