1

I have a project that I publish to Azure Artifacts:

<Project Sdk="Microsoft.NET.Sdk">    
    <PropertyGroup>
        <TargetFramework>netstandard2.1</TargetFramework>
        <DebugType>portable</DebugType>
        <Version>1.0.11</Version>
        <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
        <IncludeSymbols>True</IncludeSymbols>
        <SymbolPackageFormat>snupkg</SymbolPackageFormat>
        <PublishRepositoryUrl>true</PublishRepositoryUrl>
        <EmbedUntrackedSources>true</EmbedUntrackedSources>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.1.1" PrivateAssets="All"/>
    </ItemGroup>
</Project>

Now I also want to publish the appropriate symbols in order to debug that package. Thus I followed the instructions from https://learn.microsoft.com/azure/devops/pipelines/artifacts/symbols?view=azure-devops#publish-portable-pdbs-to-azure-artifacts-symbol-server. My pipeline contains this:

steps:
... omited for brevity
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration Release'
- task: DotNetCoreCLI@2
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    nobuild: true
    includesymbols: true
    versioningScheme: 'off'
- task: DotNetCoreCLI@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'myfeed'
- task: PublishSymbols@2
  inputs:
    SearchPattern: '**/bin/**/*.pdb'
    IndexSources: false
    SymbolServerType: 'TeamServices'

When I debug my consuming app, that references the package, and take a look into the currently loaded modules, I see my package with its symbols being loaded. However When I step into any of its types, just nothing happens and debugger steps to the next line of my consuming app.

This are my VS-settings for Debugging:

enter image description here

As you can see "Just my code" is disabled, and "Source link support" as well as "Source server support" are enabled.

I also tried to set the DebugType of my project to embedded, in order to embed the PDB into the assembly. However that didn't change anything. The symbols are loaded, but somehow SourceLink isn't able to get the information from them.

EDIT: my package is deployed with Release-configuration, instead of Debug.

MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111

1 Answers1

0

Double-check the 2020 articles from [Claire Novotny](https://twitter.com/clairernovotny (PM on the @NuGet team working on @dotnet at Microsoft):

There might be an issue with Source Linking, especially if your repository is private and there is an authentication issue.
Check also the build log for any issue related to PDB files publication.

Even with correct symbols, you might not be able to step into code if "Just My Code" is enabled in the debugger settings. "Just My Code" is a debugger feature that, when enabled, lets the debugger ignore code that is not your own. Check this setting in Tools -> Options -> Debugging -> General and uncheck the "Enable Just My Code" box if it is checked.

You have enabled EmbedUntrackedSources, which is usually a good idea, but if the sources are not being embedded correctly, it could cause issues.

To inspect PDB files and check the information they contain, you will need to use a specialized tool like dotPeek or PDB2PDB, although the latter has been recently archived. These tools can help you verify that the PDB files contain the expected debug information and source code paths.

Source Link is useful, as it embeds the source control information into the PDBs, allowing the debugger to fetch the correct version of the source code from the source control system.

That sounds like a good plan. If "Just My Code" is disabled and "Source Link support" is enabled, it seems like your Visual Studio settings are correct.

Make sure:

  • the PDB files (symbols) must match exactly with the DLLs (compiled code) they were built with. If there is a mismatch, the debugger will not be able to use the PDBs to step into the code.

  • the PDB files are being published to the symbol server in your Azure Pipelines configuration.

Once you have confirmed these points and if you are still encountering issues, you may want to try debugging with a more verbose logging level. In Visual Studio, you can enable symbol load logging by navigating to Debug > Options > Debugging > Output Window > Module Load Messages and setting it to Verbose. This could provide more information on what's happening when the symbols are loaded.

Another thing you can do is to manually load the symbols for a specific module in the Modules window during debugging. Right-click on the module and select Load Symbols. If the symbols are not loaded or there is an error, it could give you more information about the issue.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @MakePeaceGreatAgain "my pdb's are binary glibber." True: I have edited the last part of the answer with more details. – VonC Jun 09 '23 at 12:30
  • "If the symbols are not loaded or there is an error" I already mentioned, that "When I debug my consuming app [...] and take a look into the currently loaded modules, I see my package with its symbols being loaded". I will enable logging the loading of modules, though. – MakePeaceGreatAgain Jun 09 '23 at 12:35
  • hmmm, can only set it on or off, no verbose-mode in VS2022 – MakePeaceGreatAgain Jun 09 '23 at 12:36
  • So it's not an issue about the symbol not being loaded, but about SourceLink not getting the URLs of the files from it. – MakePeaceGreatAgain Jun 09 '23 at 12:41
  • @MakePeaceGreatAgain That makes senses: Source Link provides the mapping between the compiled code and the corresponding source code. It embeds URLs into the PDB files for the source code files. When you step into the code, the debugger uses these URLs to download and display the correct version of the source code. The command `sourcelink print-json ` should print the JSON Source Link data embedded in the PDB file. You can check if the URLs are correct and accessible. – VonC Jun 09 '23 at 12:48
  • Any idea how I can do that with a release-package? Calling `sourcelink print-json` on that release-pdb returns this: `{"documents":{"/home/vsts/work/1/s/*":"https://dev.azure.com/myrog/myproject/_apis/git/repositories/ClassLibrary2/items?api-version=1.0&versionType=commit&version=665f456bcb46dc0ca8996ce05f84a9df9749594c&path=/*"}}`. However VS doesn't dive into that file. – MakePeaceGreatAgain Jun 09 '23 at 13:59
  • @MakePeaceGreatAgain That URL is an Azure DevOps API call that should return the content of a file in the repository at a specific commit: Make sure that the URL is accessible, and it returns the source code file as expected. You can test this by replacing the asterisk (`*`) at the end of the URL with the path to a source code file relative to the repository root. Remember that this will need to be URL encoded. For example, for a source file at `src/MyClass.cs`, the end of the URL would be `&path=%2Fsrc%2FMyClass.cs`. – VonC Jun 09 '23 at 17:31
  • I get the correct source-code within my browser using the mentioned URL (even without URL-encoding the path) – MakePeaceGreatAgain Jun 12 '23 at 04:08
  • @MakePeaceGreatAgain so... the Source Link URLs embedded in your PDB files are correctly pointing to the source code on your Azure DevOps repository. Good! Anything in the VSCode logs? – VonC Jun 12 '23 at 09:59