Reputation: 29009
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!
Upvotes: 8
Views: 2609
Reputation: 1500475
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.
EDIT: As noted in comments, there are also PowerCommands for Visual Studio 2010.
Upvotes: 13
Reputation: 2736
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 ;)
Upvotes: 2
Reputation: 415735
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.
Upvotes: 1
Reputation: 91825
ReSharper can do this for you (among other reformatting options) and it allows you to do an entire solution in one go.
Upvotes: 1