1

I have created a new Visual Studio Package that when loaded creates a Tool Window that looks like this:

enter image description here

It is comprised of some controls with canvases and such that draw shapes in 2 or 3 dimensions. Right now they work in the initialization step to create the objects you see above. For this tool to be useful I would like to call a method on those controls to pass it other objects to draw. For example, I am debugging some code with points and lines and want to see them graphically. (Perhaps using the Immeadiate Window? or something similar?) I would like to be able to call GeometryVisualToolWindow.DrawObject(myCircle);

How can I access public methods within the package and pass arguments?

I don't want to use a debugger visualizer because I want to be able to selectively add and remove objects from the scene, where a debugger visualizer will only show the single object. (e.g. I want to see if two lines intersect, etc.)


Update

I have attempted to use DTE.Debugger.GetExpression to solve the problem but after adding the appropriate references, I get this:

enter image description here

Community
  • 1
  • 1
jth41
  • 3,808
  • 9
  • 59
  • 109
  • What do you want to call them from? Arbitrary code running with a debugger attached? – SLaks Oct 07 '14 at 15:38
  • Pretty much yes, I am imagining the Immediate window. You can look at [this question](http://stackoverflow.com/questions/26105685/access-variables-from-the-locals-watch-autos-or-immediate-windows). Where it is what I really want to do. but I want to see multiple objects at once. where in a debugger visualizer I would only see a single object – jth41 Oct 07 '14 at 15:41

1 Answers1

0

I'll give you an idea how to execute arbitrary code in visual studio debugging session.

See automation model: http://i.msdn.microsoft.com/dynimg/IC75297.gif

You have access to the instance of DTE.Debugger, this is described here: http://msdn.microsoft.com/en-us/library/aa291845(v=vs.71).aspx (Visual Studio Debugger Object Model).

You then can choose:

1) Execute the actual statement in VS debugger(ExecuteStatement). This means you need to take care of loading all your assemblies into specific debugger session. The loaded assembly needs to take care of adding static function that user can call. Such as GeometryVisualToolWindow.DrawObject(myCircle);. The method needs to communicate with VSPackage.

OR

2) Use GetExpression("myVariable.SerializeToBase64()") from your VSPackage, and voila, you have serialized instance of your myVariable. Ofcourse, you first need to inject such functionality.

http://msdn.microsoft.com/en-us/library/aa291625(v=vs.71).aspx

jth41
  • 3,808
  • 9
  • 59
  • 109
Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
  • Not bent on using the immeadiate window. just seemed like a place to start – jth41 Oct 07 '14 at 17:53
  • Well, all those windows(immediate window, autos, locals, ..) afaik depend on DTE.Debugger. You have access to current stackframe, meaning you can get list of all locals, and each local has expression which you can then check. The problem is transporting the representation from VS debugging session to VS Package as these two live in completely different context. – Erti-Chris Eelmaa Oct 07 '14 at 18:11
  • So if I understand correctly, I will have a method (lets say attached to a button on my package's window) that calls DTE.Debugger.GetExpression("myVariable.LineSegments") or something similar that will return something drawable and I will draw those lines – jth41 Oct 07 '14 at 18:18
  • That's right. You need to remember that you are going to get back only values of type "string". It's not like you can receive the "actual" object – Erti-Chris Eelmaa Oct 08 '14 at 09:02
  • View my edit on the question. I cant seem to get DTE.Debugger.GetExpression to work. I get `Error: An object reference is required for the non-static field, mehtod, or property 'EnvDTE._DTE.Debugger.get'` – jth41 Oct 08 '14 at 13:17
  • That's not how you access DTE. http://msdn.microsoft.com/en-us/library/ee834473.aspx – Erti-Chris Eelmaa Oct 08 '14 at 14:51