Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach sources to referenced assembly in Visual Studio

I am fairly new to Visual Studio, coming from Java development on Eclipse. Among other things I sorely miss from Eclipse is an ability to view source of binary assemblies.

In Eclipse I can attach reference to source code for a referenced jar and after that it is dead easy to navigate to the source, add breakpoints and debug those as though I have the libraries in my workspace.

Up to this point I have not managed to attach source code to an assembly reference.

Is it possible? How do I go about doing that (given that I do have access to the source code for this library)?

like image 260
Roland Tepp Avatar asked Mar 20 '11 12:03

Roland Tepp


People also ask

How do I add a project reference in Visual Studio 2019?

A reference is essentially an entry in a project file that contains the information that Visual Studio needs to locate the component or the service. To add a reference, right-click on the References or Dependencies node in Solution Explorer and choose Add Project Reference.

What is referenced assembly?

Reference assemblies are a special type of assembly that contain only the minimum amount of metadata required to represent the library's public API surface.


2 Answers

Using VS2010 - you will first need to compile your referenced assemblies with debug symbols.

A couple of options are then:

  1. Find an object which you want to debug in Object Browser. Right click -> Navigate To -> Sources From Symbol Files.
  2. Step through your code until you step into the referenced assembly. At this point a dialog will pop up asking where the source files are. If it doesn't, or you cancelled it, then a "Browse to Find Source" will appear on the right. If this is greyed out, then that may be because you are referencing a release assembly.
like image 107
Joe Sarre Avatar answered Oct 11 '22 23:10

Joe Sarre


If you use ReSharper, you can enable it by going to ReSharper / Options / External Sources, and move up "Sources from symbol files". Then in the tab "Sources from symbol files", click "Advanced" and there you can map source folders.

This is a copy of the answer here, but I wanted to include it here so if you, the reader, have stumbled upon this link you have the answer too.

like image 5
Frank Bryce Avatar answered Oct 12 '22 00:10

Frank Bryce