Skip to content

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:

  1. Condition: The target runs only if $(CopyLocalLockFileAssemblies) is true, which means it will only execute when the project is copying local dependencies (e.g., for executables or self-contained deployments).

  2. 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.

  3. 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:

  1. Go to Tools > Options.

  2. Navigate to Debugging > General.

  3. 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.

  1. Start debugging your application (F5).

  2. Open the Modules window (Debug > Windows > Modules).

  3. Look for the assemblies you are debugging. If the .pdb files are loaded correctly, you should see Symbols loaded in the Symbol Status column.