I created a custom project template associated with a custom project type. The solution depends heavily on MPF for Projects - Visual Studio 2012 framework.
What i would like to do next is override the default "Build" (F6) and "Start without debugging" (ctrl + F6) events for this custom project type. The solution itself will be deployed as a VSIX package.
Any help is appreciated.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With