Remove and Sort Those Ugly “using-Statements”
Visual Studio 2008 has lots of goodies in it, like LINQ syntax, CSS editing, and testing tools. There’s a lesser-known feature which I really appreciate though – the “Remove and Sort Usings” command in the C# editor.
You activate the command by placing your cursor over the using statements and clicking on the right mouse-button.
Using this groovy tool, I’ve been able to go through my old ugly C# files and get rid of all the superfluous using statements, then tidy them up, all at the click of a button. It’s something I always wanted to do, but had no time for, and didn’t want to pay for an extra tool to do it for me.
The only problem with the feature is that you have to go through every file and right-click on the “using” statements to tidy them up. That can get a bit tedious, but it’s worth it.
But now it’s the Visual Studio Extensibility Team to the rescue!
The VSX team at Microsoft have just released PowerCommands for Visual Studio 2008. It’s a free tool for Visual Studio with loads of new tools for making a VS-developer’s life easier. And one of those new tools is a Remove and Sort Usings command at the project level.
You activate it with a right-click on the project itself.
The tool then does the same Remove and Sort command for every file in the project.
Tip: Make sure your project is buildable before using the tool. If there is an error stopping the build from running, you will get dialogs asking you to confirm every change in every file.
PowerCommands for Visual Studio 2008 also contains commands for:
- Collapse Projects
- Copy Class
- Paste Class
- Copy References
- Paste References
- Copy As Project Reference
- Edit Project File
- Open Containing Folder
- Open Command Prompt
- Unload Projects
- Reload Projects
- Remove and Sort Usings
- Extract Constant
- Clear Recent File List
- Clear Recent Project List
- Transform Templates
- Close All
So, where can you get the tool?
The official site for PowerCommands is at the Visual Studio Gallery, but when you get there, you won’t see a download button. You actually have to click the “Learn More” button to go to the download page at the MSDN code gallery.
You can read more about PowerCommands on the Visual Studio Team Extensibility blog.