You can intercept any command coming from the Visual Studio UI in VSPackage. To do this, you should subscribe to the desired event of DTE.Events.CommandEvents
. You have to pass GUID and Id to CommandEvents.
private void Initialize()
{
var dte = GetService(typeof(SDTE)) as EnvDTE.DTE;
_startCommandEvents = dte.Events.CommandEvents["{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 295];
_startCommandEvents.BeforeExecute += OnLeaveBreakMode;
}
private void OnBeforeStartCommand(string guid, int id, object customIn, object customOut, ref bool cancelDefault)
{
//your event handler this command
}
Your event handler has ref bool cancelDefault
parameter, passing in cancelDefault
the TRUE you cancel the VS command, thereby replacing VS behavior by their.
To get GUID and Id command you can use VSIP Logging feature. To enable this feature, set the value of registry key:
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\General] "EnableVSIPLogging"=dword:00000001
and restart Visual Studio IDE. Then using Ctrl-Shift, click on a menu item and you'll get a message like this:
Guid and CmdID from message are a required parameter for CommandEvents.
If you are implementing a new language (create a new type of project), it is more correct to add the custom Debug Engine and MSBuild integration. You can see examples of such implementation in IronPython or Nemerle projects.