views:

885

answers:

4

Visual Studio 2008 got two great features for c#, which is called "sort using directives" and "remove unused using directives".

I'd like to call the "sort using directives" every time I format the code using ctrl+k,ctrl+d.

Or, even better, I would like to be able to reformat all c#-source files in a project, and call "sort using directives" for all source files.

How can I do this? Opening every cs-file by hand and typing these functions before every checkin is tedious!

+8  A: 

You can do it all for a solution or project using "PowerCommands for Visual Studio 2008". After installation, you just need to right-click on a project or solution and "Remove and Sort Usings" is in the context menu.

Jon Skeet
Yeah, cool. It even can reformat and sort using on file save.Just what I was looking for, thanks!
Sam
Sam
A: 

ReSharper can do this for you (among other reformatting options) and it allows you to do an entire solution in one go.

Roger Lipscombe
It would be nice if you could also say how to do this :). For the less initiated .
sirrocco
+1  A: 

I recommend you record a macro of you invoking the feature manually. Then you can just save the macro and put a button for it on the toolbar. This way you'll also have a foot in the door to get started really customizing your IDE.

Joel Coehoorn
+1  A: 

Another option is CodeMaid, a free and open source Visual Studio extension. It allows you to sort usings, remove usings, format document, remove/insert blank lines, remove whitespace, and quite a few more cleanups. It can run on save, solution wide, etc. Follow the link to the visual studio gallery to see more details.

It also lets you conditionally enable/disable individual portions, so with it you can disable remove unused usings and do sort only if you want as you mentioned in the comments.

Disclaimer: I wrote it ;)

Steve Cadwallader