Symbols & SourceLink
A consumer of your package hits an exception inside your code. With nothing else, their debugger shows a stack trace with method names and no source. Two pieces make "step into the library" work: symbols (the .pdb that maps IL back to source lines) and SourceLink (a map inside the PDB from source paths to URLs, so the debugger can download the exact source file for the commit that was built).
Symbol packages
mkdir greet && cd greet
cat > Greet.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<PackageId>Ada.Greet</PackageId>
<Version>1.0.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
</Project>
XML
echo 'namespace Ada; public static class Greeter { public static string Hello(string n) => quot;Hello, {n}!"; }' > Greeter.cs
dotnet pack -o out -nologo -v:q
ls out
echo "--- the .nupkg"
unzip -Z1 out/Ada.Greet.1.0.0.nupkg | grep lib/
echo "--- the .snupkg"
unzip -Z1 out/Ada.Greet.1.0.0.snupkg | grep lib/Ada.Greet.1.0.0.nupkg
Ada.Greet.1.0.0.snupkg
--- the .nupkg
lib/net10.0/Greet.dll
--- the .snupkg
lib/net10.0/Greet.pdb
The DLL goes into the normal package and its PDB into a separate symbol package (.snupkg). When you push the .nupkg to nuget.org, dotnet nuget push pushes the matching .snupkg alongside, and nuget.org's symbol server then serves the PDB to debuggers on demand. Consumers who never debug don't download it.
Alternatives, set with DebugType:
| Choice | Effect |
|---|---|
portable + .snupkg (above) |
small package, PDB from a symbol server |
embedded |
PDB inside the DLL; no symbol server needed, slightly bigger DLL |
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</…> |
PDB next to the DLL in the .nupkg (simple for private feeds without a symbol server) |
SourceLink
Since .NET 8 the SDK includes SourceLink for GitHub, GitLab, Azure Repos and Bitbucket: if the project is in a git repository whose origin is on one of those hosts, the build records the commit and a URL pattern. No package reference is needed any more (the Microsoft.SourceLink.GitHub package seeded on this machine is what older SDKs needed and what you'd use to pin a specific version).
mkdir greet && cd greet
git init -q
git remote add origin https://github.com/ada/greet.git
cat > Greet.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<PackageId>Ada.Greet</PackageId>
<Version>1.0.0</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>
XML
echo 'namespace Ada; public static class Greeter { public static string Hello(string n) => quot;Hello, {n}!"; }' > Greeter.cs
printf 'bin/\nobj/\nout/\n' > .gitignore
git add -A && git commit -qm "Greeter"
dotnet pack -o out -nologo -v:q
cat obj/Release/net10.0/Greet.sourcelink.json; echo
unzip -p out/Ada.Greet.1.0.0.nupkg Ada.Greet.nuspec | grep repository
git rev-parse HEAD{"documents":{"/_/*":"https://raw.githubusercontent.com/ada/greet/173eaaed2fd015a872fda87f17d0067cc4671fd8/*"}}
<repository type="git" url="https://github.com/ada/greet.git" branch="refs/heads/main" commit="173eaaed2fd015a872fda87f17d0067cc4671fd8" />
173eaaed2fd015a872fda87f17d0067cc4671fd8
Greet.sourcelink.jsonmaps the mapped source root/_/(from ContinuousIntegrationBuild) toraw.githubusercontent.com/ada/greet/<commit>/. It is embedded in the PDB; a debugger that needs/_/Greeter.csdownloads it from that URL.PublishRepositoryUrl=truewrites the repository URL and commit into the.nuspec, so anyone can find the exact source of a package version.EmbedUntrackedSources=trueembeds generated files that aren't in git (obj/…/AssemblyInfo.cs, source-generator output) directly into the PDB, because no URL can serve them.- Builds from a dirty working tree still get the HEAD commit, which is one reason official packages should come from CI, from a clean checkout.
The NuGet Package Explorer shows a "Source Link: valid" check for a package, and dotnet-validate (a global tool) checks SourceLink, deterministic builds and compiler flags of a .nupkg from the command line.
Test yourself
What does a .snupkg contain?
- The source code
- The PDB symbol files for the package's assemblies
- A signed copy of the .nupkg
- The package's README
How does SourceLink let a debugger show a library's source?
- The source is copied into the DLL
- The PDB contains a map from source paths to URLs at the exact commit, and the debugger downloads the files
- It decompiles the IL
- It asks NuGet for the source package
Why set EmbedUntrackedSources=true?
- To shrink the package
- Generated files that aren't in source control can't be fetched by URL, so they're embedded in the PDB
- To include the .git folder
- To sign the package