Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find Symbol Source code when debugging Nuget package

I have a build server that builds an internal Nuget package. When I use that package and try to step into a method it doesnt work.

All symbols are published to my symbols server and I have enabled this in my VS settings.

If I check the Modules window I see that the Nuget DLL is there and the correct symbols are loaded for it and from the symbols server.

However when I try to step into the code it jumps right over the method. If I use the call stack to specifically view that line of code it says "ClientBase.cs not found". If I expand the "Source Search Information" I see this:

Locating source for 'C:\Build Agent\vsts-agent-win7-x64-2.117.1_work\1\s\ClientsShared\Class\ClientBase.cs'. (No checksum.)

The file 'C:\Build Agent\vsts-agent-win7-x64-2.117.1_work\1\s\ClientsShared\Class\ClientBase.cs' does not exist.

Looking in script documents for 'C:\Build Agent\vsts-agent-win7-x64-2.117.1_work\1\s\ClientsShared\Class\ClientBase.cs'...

Looking in the projects for 'C:\Build Agent\vsts-agent-win7-x64-2.117.1_work\1\s\ClientsShared\Class\ClientBase.cs'.

The file was not found in a project.

Looking for source using source server...

The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: C:\Build Agent\vsts-agent-win7-x64-2.117.1_work\1\s\ClientsShared\Class\ClientBase.cs.

The debugger could not locate the source file 'C:\Build Agent\vsts-agent-win7-x64-2.117.1_work\1\s\ClientsShared\Class\ClientBase.cs'.

Why is it looking for the source code on the Build Agent? Should this not be stored within the PDB on the Symbol Server?

like image 975
Chris Avatar asked Oct 16 '22 14:10

Chris


1 Answers

What's likely happening is that the PDB file that you have added to your NuGet package is not the indexed file. It is the original file as built by MSBuild.

Are you using TeamCity? Do you have only one build configuration? If so, then this is certainly the case.

TeamCity indexes any PDB files that are created as Artifacts (assuming that you have the plugin installed). Here's the catch: indexing your PDB means modifying your PDB. The modified PDB will be found in the build artifacts. Since there is no point during your build that the modified (indexed) PDB will be available, you have to split this into two configurations.

The Build Configuration

Create a build configuration called Build and edit the configuration settings. Look at General Settings. Artifact Paths lists the files that will be output from your build.

This text box lists a series of rules: copy files matching this pattern to artifacts at that path. You want to add rules to copy your dll, pdb, sln, csproj, nuspec, and packages.config files to artifacts using the correct relative structure. You should end up with something like this:

MyProject.sln
MyProject/bin/Release/MyProject.pdb => MyProject/bin/Release
MyProject/bin/Release/MyProject.dll => MyProject/bin/Release
MyProject/MyProject.csproj => MyProject
MyProject/MyProject.nuspec => MyProject
MyProject/packages.config => MyProject

Run this build and verify that you get the expected artifacts. Check the Build Log and make sure that it includes the steps “Indexing symbol sources” and “Publishing symbol sources”. Then click on the Artifacts tab of the successful build, and these six files should be listed, and in the correct directory structure.

The NuGet Configuration

Since TeamCity modifies your PDB when it indexes it, you cannot generate the NuGet package in the Build configuration. You need a second configuration. This one we will call “NuGet”.

Create a new build configuration called NuGet and edit the configuration settings. Look at Dependencies, and add a new Artifact Dependency. This should depend upon the Build configuration and get artifacts from the last successful build. Bring in all of the files that we output from the Build configuration:

**/*

Create a Build Step called "NuGet Install". This should be a "NuGet Install" step to restore all of your dependencies. Enter the name of your *.sln file.

Create a second Build Step called "NuGet Pack". This should be a “NuGet Pack” step. The specification file will actually be your csproj, not your nuspec! Just give the full path, such as MyProject/MyProject.csproj. Set the output directory to “Packages” and check “Publish created packages to build artifacts”.

The NuGet Specification

To complete the picture, you need to be sure that the *.nuspec file includes the PDB file. You can do this by listing the DLL and PDB as files within the *.nuspec. Add a section below (not inside of it) and list both of those files. It should look something like this:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <copyright>Copyright 2018</copyright>
  </metadata>
  <files>
    <file src="bin\Release\MyProject.dll" target="lib\net461" />
    <file src="bin\Release\MyProject.pdb" target="lib\net461" />
  </files>
</package>
like image 139
Michael L Perry Avatar answered Oct 20 '22 22:10

Michael L Perry