Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debug a project with references in Visual studio

I have two separete c# projects. One is a helper library that is included as a reference to another main project. The main project solution only has a reference to the helper library and not the entire source code there. I want to run the main project but also want to be able to debug and step through the code in the helper code. How can I do that? I have the source code for both projects.

like image 983
randomThought Avatar asked Apr 05 '11 20:04

randomThought


People also ask

How do I Debug a reference DLL in Visual Studio?

Select the C# or Visual Basic DLL project in Solution Explorer. Select the Properties icon, press Alt+Enter, or right-click and choose Properties. In the Debug tab, select Open Debug launch profiles UI. In the Launch Profiles dialog box, select the Create a new profile icon, and choose Executable.

How do you check a project reference in Visual Studio?

You can also right-click the project node and select Add > Project Reference. If you see a References node in Solution Explorer, you can use the right-click context menu to choose Add Reference. Or, right-click the project node and select Add > Reference.

How do I Debug an external project in Visual Studio?

Right click on solution -> Add Existing Project -> then select the . csproj file of your external library (project B). Again in visual studio right click on (project A) -> Add -> Project Refference... -> and then add checkmark on your external library which you want to debug (project B).


2 Answers

If you compile the library on your machine and include the .PDB files your visual studio should be able to step into the code if you use the Step In command while debugging.

If you want to breakpoint in that code, file->open then select the .cs file from the other project and set a breakpoint.

Hover your mouse over the breakpoint and it'll say something like:

At Something.cs, line 12 character 34 ('MyOtherLibrary')

This means the debugger is attached to the code in your helper library.

like image 102
Aren Avatar answered Sep 20 '22 15:09

Aren


2 more things:

  • make sure PDB is loaded for the DLL you are adding. Check if in the "Debug -> Windows -> Modules" window the DLL in question have PDB from the correct path. If not you can force VS to load PDB by right click -> load symbols on the module in the same window.

  • if everything else fails try to turn off "my code only" in Tools -> Options -> Debugging. This will make VS to try load PDBs for all Dlls and allow breaking on throw for every exception.

like image 31
Alexei Levenkov Avatar answered Sep 19 '22 15:09

Alexei Levenkov