Executing a Command

You can execute commands in two ways. The DTE object has an ExecuteCommand method you can use to trigger a command based on its name.

_applicationObject.ExecuteCommand("Window.CloseDocumentWindow");

The Commands collection is also a vehicle for launching commands through its Raise method. Instead of using the command’s name, the Raise method uses its GUID and ID to identify the command.

Commands2 commands = (Commands2)_applicationObject.Commands;Command cmd = commands.Item["Window.CloseDocumentWindow"];object customIn;object customOut;commands.Raise(cmd.Guid, cmd.ID, customin, customout);

Some commands accept arguments. The Shell command is one example. It is used ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.