Search code examples
c#vb.netvisual-studiovisual-studio-2017vsix

Visual Studio Extension: How to disable native command?


I build an extension that manages correctly Git Modules and, to do so, I have a folder in the solution called SubModules.

I managed to add my context menu to the solution file and to the project files, but I would like to disable some native commands when right-clicking on my SubModules folder (i.e. Remove, Add).

Is there a way to disable such native command?

I tried exploring EnvDTE80.DTE2.Commands, but no luck and searching tells me how to disable my own commands (which I already know how).

My extension is developed in C#, but an answer in VB.Net is alright too.


Solution

  • You can subscribe to commandEvents.BeforeExecute, check the command name in the handler and set CancelDefault = true to disable a command. See Add confirmation before running Build.RebuildSolution and other rebuild commands.