Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Visual Studio extensions

I'm just writing a VSIX extension for Visual Studio 2010 and can't figure out how to debug it.

One obvious method is to output messages. Extension template uses Trace.WriteLine(). But where to find it's output?

like image 465
Lu55 Avatar asked Feb 14 '12 17:02

Lu55


People also ask

How do I Debug an extension?

Navigate to the chrome extensions management page at chrome://extensions and ensure developer mode is on. Click the Load Unpacked button and select the broken extension directory.

How do I Debug a plugin in Visual Studio?

In your Visual Studio project, set a break point in your plug-in class. In your Visual Studio project, select Debug > Attach to Process…. Select the PluginRegistration.exe process and click Attach. You should see that the Plug-in Registration tool is now running in debug mode.

How do I Debug code in Visual Studio Code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


3 Answers

Visual Studio Extensions can be debugged like any other application. You just need to setup the debug experience to launch devenv with the loaded extension. Try the following

  • Right click on the project and select Properties
  • Go to the Debug Tab

Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it's located at

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe

On a non x64 machine though you can remove the " (x86)" portion.

Then set the command line arguments to /rootsuffix Exp. This tells Visual Studio to use the experimental hive instead of the normal configuration hive. By default VSIX extensions when built will register themselves in the experimental hive.

Now you can F5 and it will start Visual Studio with your VSIX as an available extension.

like image 120
JaredPar Avatar answered Nov 06 '22 23:11

JaredPar


The accepted answer by @JaredPar is technically correct, but suffers from the fact that you need to redo it for every developer, every time you get a fresh copy of the code, and any time the csproj.user file is deleted. When you do it that way, the settings are saved in the csproj.user file.

A better option is to put the settings in the csproj file so they are not lost. Unfortunately, Visual Studio does not allow you to do this automatically, so you need to manually add the settings. Luckily, the settings are the same for any project.

Right-click and unload the project, then right click again and edit the csproj project file file. In the XML, add the following to the first PropertyGroup, for example right after TargetFramework.

<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>

This has the following advantages;

  • It sets it up for debug and release
  • It runs whatever version of Visual Studio you are currently running
  • It is checked into source control, so every developer doesn't have to remember how to do it :)

As @MBulli states in the comments, if you have made the changes in the accepted answer, delete your *.csproj.user file because the settings in it will override the ones you added to the main csproj file.

like image 42
Rob Prouse Avatar answered Nov 07 '22 00:11

Rob Prouse


The OutputWindowHelper.OutputString method writes to the 'General' output window pane (Ctrl Alt o). I added this line in my .csproj references to get this in VS 2013

<Reference Include="Microsoft.VisualStudio.Services.Integration, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

Also see this answer.

like image 25
tcb Avatar answered Nov 06 '22 23:11

tcb