Louis Rhys
Louis Rhys

Reputation: 35637

Visual Studio: how to debug a library with an external executable?

I am developing a class library. The library is to be used by another program, an .exe with no source code. The library file location is passed as a parameter to this exe, for example by running: prog.exe lib.dll

I would like to debug the library using this .exe (using debug tools such as breakpoints, etc.) How do I use Visual C# to do this?

I found a possible way, which is creating a one-line program which execute prog.exe lib.dll. Surely there is a better way?

Upvotes: 8

Views: 5111

Answers (3)

Soundararajan
Soundararajan

Reputation: 2194

  1. You can probably try windbg. with the sos extension, it is mearly possible to everything you do with Visual Studio.
  2. If all you want is to debug the library, then why can't you load that library into an exe you created and step inside the library,

Upvotes: 0

Richard
Richard

Reputation: 108975

In the project's debug options select "Start External Program" and enter the path of the exe. On starting debugging VS will start the exe, attach to it as a debugger.

When your library is loaded any breakpoints on your code will activate.

One caveat: with an external program ensure it is loading the dll you are building, things can be (at best) odd if it is loading a different version that doesn't match the source code.

Upvotes: 3

Fredrik Mörk
Fredrik Mörk

Reputation: 158289

If you already have an external program that use your library (which then also is a .net application, I will assume), you can start that program and attach the debugger to the process (Debug -> Attach to process in the menu). Then you will be able to set breakpoints in your class library code and debug it. Make sure that the exe uses a dll and pdb file that is in sync with your code (the latest build).

Upvotes: 1

Related Questions