Debugging Visual Studio Extensions

Writing Visual Studio Extensions has gotten much easier with recent versions of Visual Studio, but figuring out how to debug them can be hard. When you debug an extension, you run it in an instance of Visual Studio using a separate set of settings called an experimental hive. When you launch this from Visual Studio, it takes care of installing your extension and the debugger is attached to Visual Studio itself.

The usual recommendation is to edit the project’s Properties and enter the information in the Debug Tab. This works, but that information is not saved in the project file, so you need to do it whenever you get a clean copy of the source. I prefer saving the information in the project file itself.

Editing the Visual Studio Extension Project File

Unload the extension project in Visual Studio by right clicking on it and selecting Unload Project. Next, edit the project by right clicking and selecting Edit MyExtension.csproj.

Add the following XML after the first </PropertyGroup> end tag in the project.

<propertygroup>
  <!-- Common debugging support -->
  <startaction>Program</startaction>
  <startprogram>$(DevEnvDir)\devenv.exe</startprogram>
  <startarguments>/rootsuffix Exp</startarguments>
</propertygroup>

Please note, the XML above should be PascalCase, in other words, propertygroup should be PropertyGroup. WordPress keeps converting the code to lowercase. If anyone knows how to fix that, please let me know in the comments.

This runs the current version of Visual Studio using the /rootsuffix Exp command line. If you save the file and reload it, you will now see the options in the Debug Tab of the project’s Properties.

Debugging a Visual Studio Extension

If you see something different, delete your .csproj.user file and don’t change the values here otherwise they will be saved in the .csproj.user file. If you want to make changes, you must hand edit the file.