locked
Command invocation from VS addon RRS feed

  • Question

  • VS allows to execute various commands from the Commands Window http://msdn.microsoft.com/en-us/library/c338aexd.aspx. For example you may use "Debug.ListCallStack" in the Commands Window (or ">Debug.ListCallStack" in the Immediate Window). Are these commands accessible from VS extensions? I tried Debugger.GetExpression - it doesn't work.


    • Edited by EliMLi Sunday, September 16, 2012 7:03 AM
    Sunday, September 16, 2012 7:01 AM

Answers

  • This is mostly true, though if a command is context sensitive finding the proper handler (which is necessary for invocation) requires the handler be in the command route when you invoke the command.

    This could be a specific window is activated or it could actually be impossible (i.e. when you call IVsUIShell::ShowContextMenu you can pass an IOleCommandTarget to use while the context menu is being displayed. If that handler is required for some command, and that handler is not present anywhere else in the route, no one would ever be able to execute your command since only you can call ShowContextMenu with the proper handler).

    That said, such a command or situation should yield a Command object whose IsAvailable property is false, so as Carlos suggested, you should check that.

    Ryan

    • Marked as answer by EliMLi Tuesday, September 18, 2012 4:02 AM
    Monday, September 17, 2012 9:35 PM
  • Hi EliMli,

    Yes, when we use DTE.ExecuteCommand("Debug.ListDisassembly"), we can get the same result as commanding in command windows. We can't capture the output through the command.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by EliMLi Friday, September 28, 2012 6:24 PM
    Wednesday, September 26, 2012 3:05 AM

All replies

  • Hi,

    AFAIK, all commands are executable from extensions using DTE.ExecuteCommand. If the command is not enabled the call will fail, so you may want to check if it is available by getting the command with DTE.Commands.Item(name) and then using the EnvDTE.Command.IsAvailable property.


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    • Marked as answer by EliMLi Tuesday, September 18, 2012 4:02 AM
    • Unmarked as answer by EliMLi Sunday, September 23, 2012 3:48 AM
    Monday, September 17, 2012 10:44 AM
  • This is mostly true, though if a command is context sensitive finding the proper handler (which is necessary for invocation) requires the handler be in the command route when you invoke the command.

    This could be a specific window is activated or it could actually be impossible (i.e. when you call IVsUIShell::ShowContextMenu you can pass an IOleCommandTarget to use while the context menu is being displayed. If that handler is required for some command, and that handler is not present anywhere else in the route, no one would ever be able to execute your command since only you can call ShowContextMenu with the proper handler).

    That said, such a command or situation should yield a Command object whose IsAvailable property is false, so as Carlos suggested, you should check that.

    Ryan

    • Marked as answer by EliMLi Tuesday, September 18, 2012 4:02 AM
    Monday, September 17, 2012 9:35 PM
  • DTE.ExecuteCommand doesn't help to execute Debug.ListDisassembly command and get the output. The problem is that DTE.ExecuteCommand behaves like the expression evaluator in the Quick Watch window, while I'm trying to figure out how to execute a command in Command Window and to gets its output.
    • Edited by EliMLi Sunday, September 23, 2012 6:15 AM
    Sunday, September 23, 2012 3:49 AM
  • As Carlos and Ryan said, you can excute the command Debug.ListDisassembly. 

    Did you want to output the result to a file?
    Monday, September 24, 2012 3:00 AM
  • I can do DTE.ExecuteCommand("Debug.ListDisassembly") but how to capture the output of this command? Also it would be nice to execute Debug.ListDisassembly command and to get its output without changing the Command Window.
    • Edited by EliMLi Monday, September 24, 2012 5:45 AM
    Monday, September 24, 2012 5:42 AM
  • Hi EliMli,

    Yes, when we use DTE.ExecuteCommand("Debug.ListDisassembly"), we can get the same result as commanding in command windows. We can't capture the output through the command.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by EliMLi Friday, September 28, 2012 6:24 PM
    Wednesday, September 26, 2012 3:05 AM