Visual Studio - Attach source code to reference

Visual Studio-2008Reference

Visual Studio-2008 Problem Overview


My C# project references a third-party DLL for which I have the source code. Can I somehow tell Visual Studio the location of that source code, so that, for example, when I press F12 to open the definition of a method in the DLL, it will open up the source code, instead of opening up the "Class [from metadata]" stub code?

Visual Studio-2008 Solutions


Solution 1 - Visual Studio-2008

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.

Solution 2 - Visual Studio-2008

Looks like the answer is near the bottom of this MSDN documentation page.

> The debugger looks for source files in the following locations: > > 1. Files that are open in the IDE of the Visual Studio instance that launched the debugger. > > 2. Files in the solution that is open in the VS instance. > > 3. Directories that are specified in the "Common Properties" / "Debug Source Files" page in the properties of the solution. > > 4. The source information of the .pdb of the module. This can be the location of the source file when the module was built, or it can be a command to a source server.

To add a directory to the solution's Debug Source Files page (step 3. above):

> You can specify a network or local directories to search for source > files. > > 1. Select the solution in Solution Explorer and then choose "Properties" from the shortcut menu (i.e. right-click context menu). > > 2. Under the "Common Properties" node, choose "Debug Source Files". > > 3. Click the folder icon. Editable text appears in the "Directories containing source code" list. > > 4. Add the path that you want to search. > > Note that only the specified directory is searched. You must add > entries for any subdirectories that you want to search.

So if you just want to debug a specific file once without cluttering up your solution, just open that file up in the Visual Studio IDE; if you need to step from that file into others, you will likely need to have the other files open in Visual Studio as well.

If you often find yourself needing to debug source files outside of your solution, then you can either:

  1. Add the source files to one of your existing projects in the solution, or create a new project in the solution to house the source files. This will clutter up your solution/project, but since it will be checked into source control, all team members will automatically be able to debug into the source files.
  2. Add the directories holding the source code to the solution's "Debug Source Files". Because this change is not checked into source control, each team member that wants to debug the source files will need to do this and add their local paths. Also, if you get the solution code on a different machine, you will need to remember to perform this step again.

Solution 3 - Visual Studio-2008

One way you could do this would be to create another project in your solution, put the DLL source in there, and then from your main project, add the dependency as a project reference instead of an assembly reference. That should let you browse the source / step into it while debugging, etc.

There might be an easier way to do it, but I'm not aware of any at present.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoe DaleyView Question on Stackoverflow
Solution 1 - Visual Studio-2008Cesar ReyesView Answer on Stackoverflow
Solution 2 - Visual Studio-2008deadlydogView Answer on Stackoverflow
Solution 3 - Visual Studio-2008tzamanView Answer on Stackoverflow