This plugin wraps up 2 existing tasks (The ‘CleanupFile’ command and the ‘Optimize Namespace References’) in to a single new command ‘CleanupFileAndNamespaces’.
In order to use this plugin:
Step 0 – Requirements
This plugin requires version 13.2 of CodeRush and a non-express version of Visual Studio version 2010 or higher.
If you have a current CodeRush subscription, you can download the latest version through our download centre.
If not, you can download a 30 day trial of all of our .Net products, including CodeRush.
Step 1 – Download
This plugin is hosted on GitHub and is available as either VSIX or as Sourcecode
If you have downloaded the source, you will have to compile the plugin yourself, and then install from the VISX which the compile process creates.
Once you have the VISX, (via download or compilation) simply double click it, and follow the prompts.
Step 3 - Configuration
All that is necessary to configure this plugin, is to assign a key to the new ‘CleanupFileandNamespaces’ command.
This is done via the Shortcuts options page.
- To open the options screen either choose DevExpress\CodeRush\Options from the main menu, or use the Ctrl+Shift+Alt+O shortcut.
To locate the shortcuts options page, locate the IDE\Shortcuts item in the tree on the left, or use theicon in the upper right of the options screen.
Create a new shortcut by right clicking in an appropriate folder and choosing ‘New Keyboard Shortcut’ or ‘New Mouse Shortcut’.
Then choose a suitable key or mouse combination based on your preferences and previous choice. I usually pick Ctrl+T for testing purposes.
Next choose the ‘CleanupFileAndNamespaces‘ command from the commands dropdown.
Finally you should set the context of this command to make it only available when you are within a .vb or .cs file.
Finally click OK to accept your changes.
Create a new shortcut and assign it to the the ‘CleanupFileAndNamespaces’ command.
Step 4 – Usage
- Place your caret in any .cs or .vb file. and invoke using the configured shortcut. CodeRush will run the ‘Optimize Namespace References’ refactoring and follow that by running any configured Code Clean operations.
For example:
The following is a fresh C# Library project, with a single unused variable declared.
Assuming that you have the default settings for Code Cleanup, and you trigger CleanupFileAndNamespaces from this start position, CodeRush will remove the unused using directive and the unused declaration:
This simple plugin links together 2 often used features so that they can operate as one.
In my next post I’ll explain how this plugin works in detail.