Note: This post was written a while back but sat in draft. I’ve published this now, but I’m not sure it’s relevant to the latest versions etc. so please bear this in mind.
A Visualizer is a feature where, if you run an app. and whilst debugging you put the mouse over a variable a little debugger popup appears. You have a drop down to display the value in the variable as XML, HTML etc.
- Create class lib project
- Add references to Microsoft.VisualStudio.DebuggerVisualizers.dll and System.Windows.Forms
using Microsoft.VisualStudio.DebuggerVisualizers; using System.Windows.Forms; [ assembly: System.Diagnostics.DebuggerVisualizer( typeof(MyFirstVisualizer.DebuggerSide), typeof(VisualizerObjectSource), Target = typeof(System.String), Description = "My First Visualizer") ] namespace MyFirstVisualizer { public class DebuggerSide : DialogDebuggerVisualizer { protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { MessageBox.Show(objectProvider.GetObject().ToString()); } public static void TestShowVisualizer(object objectToVisualize) { var visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(DebuggerSide)); visualizerHost.ShowVisualizer(); } } }
TestShowVisualizer allows us to test from a console app
- Create console app
- Add reference to Microsoft.VisualStudio.DebuggerVisualizers.dll and our project reference
class TestConsole { static void Main(string[] args) { var myString = "Hello, World"; DebuggerSide.TestShowVisualizer(myString); } }
To install, copy to
{visual studio deployment folder};\Common7\Packages\Debugger\Visualizers
i.e. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers
and
MyDocuments\Visual Studio 2015\Visualizers