I often publish little samples in this blog based off MDbg (which generally show off the debugging services in some way; such as app to convert Pdb–>XML, or this harness to print all exceptions in an app). I generally call these apps “harnesses” because they run on another app (the debuggee). I’ve gotten some questions about how to build them, so here are some more details.
The big picture is that these samples just need a reference to the Mdbg dlls and then all else is good. We ship Mdbg as a source sample and also in the .NET 2.0 SDK. See here for a comparison. The key details are that:
– the sample has full source for Mdbg. The sdk version does not.
– the sample has 4 dlls to link against: Corapi, CorApi2, MdbgEng, MdbgExt. The sdk just has 1 dll, MdbgCore.
The 2 versions are very close and most test apps could be compiled against either one.
Note MDbg requires .NET 2.0. So V1.1 users are some what out of luck.
Here are more details:
- Just install the Mdbg sample (details here).
- Build it for a sanity check.
- Create a new project for your test app. My samples are mostly C# console applications
- My samples are usually a single file; so you can just copy the sample off the web page and then paste it into the newly created project file.
- For the new project, add a reference to the Mdbg dlls from the other projects (Corapi, CorApi2, MdbgEng, MdbgExt.)
- Make sure it all builds.
- Set the test app as your startup project and go. In some cases, you may need to supply command line args to the test app.
This is nice because then everything is in VS. You get intellisense for all of Mdbg, you can step between the new app and mdbg core, and you get Edit-and-continue support.
The harder way: Do it all on the Command line (no VS)
If you don’t have VS, you can still build an Mdbg app on the command line.
- Download both .NET 2.0 and the .Net 2.0 sdk. (X86 links are here and here).
- Copy the sample from the web page to some source file (eg, T.cs).
- Copy mdbgcore.dll from the sdk into the same directory as T.cs
- Compile it:
csc t.cs /debug+ /r:mdbgcore.dll
- Run t.exe. It may need some command line args.
You could also download the mdbg sample and build that without VS, and then build the test app against that; all on the command line.
Or you could build just your harness in VS, and then add a reference to mdbgcore.dll from the sdk.