Just imagine you are in Solution Explorer and you expand a few folders to find a file with an extension "xyz". When you right-click this file, you get a context menu. What I want to do be able to do is add a new/custom button to that context menu BUT ONLY for the "xyz" file type, for example.
After a lot of hunting, I am stumped. I have buttons in the main menu easy enough, but I am trying to make it conditionally present in the context of a file. If you can help, thank you in advance.
Based on Sergey Vlasov's comment, i created a VSIX project using
Dynamically add menu itemsfor test in VS2022.It can be able to add a new/custom button to that context menu BUT ONLY for the "xyz" file type,for example. Please check the following steps.This is the final run result:
Steps
1 Create a VSIX project named DynamicMenuItems.
2 When the project opens, add a custom command item template and name it FirstCommand.
After completing these two steps and you will see the project directory structure:
3 Specify a rule for when a button should be visible. In this example, the rule is that the button should be visible when the user right-clicks a .xyz file in Solution Explorer. We can express that in an attribute on the Package or AsyncPackage class like so:
See sample DynamicMenuItemsPackage.cs file about using the
ProvideUXContextRuleattribute.4 Modify the menu group created for your action to make it an “Item node menu” command instead of a “Visual Studio Menu” command. Please refer to IDM_VS_CTXT_ITEMNODE
5 Register a based on that rule in the .vsct.
6 Mark the button itself as dynamic visible.
7 Customize your context menu name.
8 Add UI Context guid that must match the one in DynamicMenuItemsPackage.cs.
see sample DynamicMenuItemsPackage.vsct file:
Note:You can refer to this guide:
https://github.com/microsoft/VSSDK-Extensibility-Samples/tree/master/VisibilityConstraints#lets-get-started