Menu: Edit -> IntelliSense -> Organize Usings -> [Remove Unused Usings, Sort Usings, Remove and Sort]; RIGHT CLICK -> Organize Usings -> [Remove Unused Usings, Sort Usings, Remove and Sort]
Command: EditorContextMenus.CodeWindow.OrganizeUsings.[RemoveUnusedUsings, SortUsings, RemoveAndSort]
Versions: 2008,2010
Published: 6/29/2010
Code: vstipEdit0070
Got issues with your Using statements? Need a little help getting them organized? No problem! You can simply RIGHT CLICK anywhere in the editorto get the Context Menu then choose Organize Usings; you should see this:
Remove Unused Usings - removes unused using directives, using aliases, and extern aliases. There are a couple of things to note about this feature. First, it should ONLY be use on code that builds as it could remove required usings if activated on code that does not build. There is an option in VS2008 (NOT VS2010) found at Tools -> Options -> Text Editor -> C# -> Advanced -> Organize Usings that will prevent you from removing usings if you code doesn't build:
Second, it only works on the active set of code. So if I have a set of usings:
And remove the unused usings; this is what I get:
However, if those usings are organized into code that has active and inactive blocks:
Then only extra usings in the ACTIVE block will be removed:
Sort Usings - will sort in this order: extern aliases, using directives, using aliases. Also, by default, it will sort usings that reference the System namespace before other using directives. So if we again have some usings:
And sort them, we get this:
Notice the Microsoft namespace is below all the System namespaces. If you don't like this behavior, you can change it by going to Tools -> Options -> Text Editor -> C# -> Advanced -> Organize Usings and deselecting the "Place 'System' directives first when sorting usings" option:
This is what you will get as a result when you sort:
Remove and Sort - Performs a remove operation then a sort operation.