VSIX: subscribe to command

108 Views Asked by At

How do I subscribe to a 3rdparty extension's command from my own VSIX extension? Such as OnClick event of an extension.

1

There are 1 best solutions below

1
On

If it is a command, you should be able to capture it using DTE.Events.CommandEvents[commandGuid, commandId].BeforeExecute (or AfterExecute). (MSDN)

If you do not know the ID and GUID you can subscribe to all commands (as both indexer parameters are optional), add logging of ID/GUID, then use the command you are interested in.

Important Note:
I believe you have to keep a reference to DTE.Events.CommandEvents[commandGuid, commandId] somewhere so it will not be garbage collected. Otherwise you may lose your subscription.