How to debug a Visual Studio Extension


I am writing a class library to extend Visual Studio but I can't figure out how to debug it.


Right click on the class library project in Solution Explorer and select properties.  This will display the property pages for the selected project.  Click on the Debug tab on the left hand side.  Under the Start Action section select the second radio button Start External Application and browse to the exe you need to start. For Visual Studio extensions find the devenv.exe version you need.  Under the Start Options selection add the following Command line arguments:
/rootsuffix Exp
Now when you press F5 to debug your class library the debugger will launch another instance of Visual Studio to load your class library and allow you to debug it.


Class libraries don't execute themselves and require an executable to load the library so we can debug it.  Therefore, we must instruct the debugger on which application to load to host our class library so we can debug it.
The command line arguments we pass for a Visual Studio extension makes sure that we don’t corrupt our registry on our machine.  That argument tells the second instance of visual studio to use an experimental hive in the registry to make any needed registry changes.  This leaves our real registry clean.
While developing an extension for Visual Studio there may become a time where the debugger has an issue starting the second instance of Visual Studio. One cause of this issue is a corrupted experimental hive.  You can execute Visual Studio from the command line passing in the following arguments to have it restore your experimental hive:
devenv.exe /setup /rootsuffix Exp /ranu

Comments are closed