Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Visual Studio to use Embedded Source code whilst debugging?

I have embedded the C# source code into a portable PDB file using the <EmbedAllSources> element in the csproj file, and I have embedded the pdb into the assembly using the <DebugType>embedded<DebugType> as described in Embedding C# sources in PDB with new csproj

My assembly looks like this:

<PropertyGroup>     <TargetFramework>netstandard2.0</TargetFramework>         <EmbedAllSources>true</EmbedAllSources>     <DebugSymbols>true</DebugSymbols>     <DebugType>embedded</DebugType>    </PropertyGroup> 

I can confirm that the pdb is type portable, and contains my source code:

enter image description here

According to the release notes for Visual Studio 15.5 the debugger should be able to use these files during debugging:

https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.5#EmbeddedSource

I'm using Visual Studio 2017 (version number 15.8.8)

However, when I F11 into the code from my assembly it asks for the sourcecode:

enter image description here

Whilst googling around there's a comment from ctaggart in the discussion https://github.com/ctaggart/SourceLink/issues/192 which says running sourcelink print-urls will print "embed" but mine doesn't, perhaps this is a hint:

enter image description here

Has anyone got this to work successfully? If so can you tell what I'm doing wrong?

like image 414
Daniel James Bryars Avatar asked Nov 06 '18 16:11

Daniel James Bryars


People also ask

How do I enable debugging code in Visual Studio?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.

How do I Debug code in source?

To use source debugging, you must have your compiler or linker create symbol files (. pdb files) when the binaries are built. These symbol files show the debugger how the binary instructions correspond to the source lines. Also, the debugger must be able to access the actual source files.

How do I use PDB files for debugging?

The easiest way to use the PDB file is to let Visual Studio do the heavy lifting - either launch your program with Visual Studio's "Debug" command (F5 by default), or run the program and use the "Attach to Process" item in Visual Studio's Debug menu.


1 Answers

Easiest way is to go to:

Debug -> Windows -> Modules

Inside this list, you should be able to find your assembly (dll/exe).

Right click it -> Load Symbols

It will ask for where to load the symbols from.

Navigate to the directory where your matching .pdb file is.

It should auto load. Stepping into, or having uncaught errors in this referenced assembly should trigger a break in that code, or ask you to navigate to the code file that corresponds to the file that threw the error.

In our process, we generally have to navigate to the nuget cache to find the pdbs for our installed nuget packages. (%UserProfile%/nuget/packages/YourPackage/VersionNumber/../..)

We also package up the source with those packages and navigate to those /nuget/packages .cs files as well, though, any corresponding .cs file should allow it to load.

like image 198
Magn3s1um Avatar answered Oct 11 '22 17:10

Magn3s1um