Thursday 30 July 2015

How to remove unused using namespaces

 Visual Studio can do this for you.
Organise Usings > Remove Unused Usings
I am using this all the time, to clean up code, and make code compilation quicker.
Or you can use PowerCommands to remove unused usings for entire projects

Install this Microsoft-created add-in, and VS 2010 will always remove and sort usings every time you save a code file (e.g. with Ctrl-S or clicking a Save button).
The option is under Tools > Options > PowerCommands > Remove and Sort Usings on save. There's also an option to automatically format the document on Save, which will make sure your code lines up, doesn't include trailing spaces, etc.
(Should you need to avoid removing and sorting usings while this is installed, just build or run your code without explicitly saving. The automatic save-on-build or save-on-run will still happen.)