For one of the Blueprints I am currently writing I had to add a menu item that enables the Blueprint user to execute a specific task (command). Adding menu items to a Blueprint is pretty easy by using the Blueprint configuration dialog. As we can see in the screenshot below we can also set the ‘visibility for the menu item by specifying a menu filter in the ‘Visibility box’ on the dialog.
The current Blueprints CTP comes with a few ‘built-in’ menu filters like: Project=roject name, FolderEndsWith=folder name, etc. (complete list can be found in de Blueprints documentation). Of course I needed a menu filter that wasn’t available out of the box. Unfortunately the documentation doesn’t say anything about adding custom menu filters but luckily a little experimenting (and Reflector ;)) was enough to get this to work.
Here are the steps to implement your own custom menu filter:
The first thing to do is to simply add the name of your new custom menu filter in the ‘Visibility’ box of the menu item you want the custom menu filter to be applied on. In this example we also pass a custom argument (‘BlaBla’) to our custom menu filter.
The second step is to actually implement the custom menu filter. This can be easily done by adding a ‘Command Extension’ project to your Blueprint solution (Blueprints menu –> Add Command Extension). This project already implements a post build event to make sure the .dll that hosts your command extension is copied to the correct location to let Blueprint Manager find it during execution of your Blueprint.
for this example we can delete all default files in the extension project and add a new class to this project that implements the ‘IMenuFilter’ interface (add a reference to the ‘Microsoft.SoftwareFactories.BASMAPI.dll’ assembly that can be found under the Blueprint installation directory).
In this class, the ‘FilterSupported’ method is used to decide whether a custom menu filter is supported in our Blueprints. Àll we have to do in this method is return ‘true’ for the custom menu filters (name) that we want to support in our Blueprint. (note that we can handle multiple custom filters here).
The ‘Visible’ method is used to decide whether the menu item that has our custom menu filter applied should be visible or not. The screenshot below demonstrates a, not very useful (and not bulletproof), implementation of a custom menu filter that only shows the menu item in case the Blueprint user right clicks the Solution (Solution Explorer) and the name of the selected Solution starts with the parameter supplied to the custom menu filter (‘BlaBla’ in this case). As said, not a very useful filter but it hopefuly demonstrates what can can be done here.

After we finished the ‘Visible’ method, we are done implementing our custom menu filter and all we have to do is make sure the Blueprints Manager knows about our custom menu filter. How?
As we can see in the screenshot below, the menus that we define in our Blueprint configuration dialog (see above) are stored in the ‘config.xml’ file of our Blueprint (located in the properties folder in our Blueprint project).
At some point, the Blueprint Manager parses this config file, searches for custom menus, detects the ‘MyCustomMenuFilter’ that we specified in our menu item and notices it isn’t one of the ‘built-in’ menu filters. At that time the Blueprint Manager checks if any additional ‘resources’ are registered for our Blueprint that might host an implementation of the ‘IMenuFilter’ interface. To make sure the Blueprint Manager can find our extension, we register our custom menu filter by adding the following (screenshot below) to the config file of our Blueprint.
After that, if the Blueprints Manager detects a menu filter that is doesn’t recognize, it will search its additional resources and find our custom menu filter implementation. It will then call the ‘FilterSupported’ and ‘Visible’ methods on our ‘CustomMenuFilters’ class to decide whether or not the custom menu item is supported and under what circumstances display our menu item.