Marek Grzenkowicz
Marek Grzenkowicz

Reputation: 17353

Is there a way to automatically sort the using directives alphabetically in Visual Studio 2005?

There is this option available in Visual Studio 2008.

Is there a similar option in Visual Studio 2005? Or something else that would accomplish such a task? An add-in, maybe?

Upvotes: 0

Views: 665

Answers (4)

edosoft
edosoft

Reputation: 17271

Resharper can remove the unused 'using' statements. I'm not 100% sure it can also sort them.

Upvotes: 1

Charles Anderson
Charles Anderson

Reputation: 20039

If you've got Visual Assist, that's got a 'Sort Selected Lines' command that will do what you need.

Upvotes: 2

Gerrie Schenck
Gerrie Schenck

Reputation: 22368

Resharper has a sort function. But it looks like all System usings are put on top, and then the rest alphabetically.

Also check this question also on optimizing usings with Resharper.

Upvotes: 1

John Källén
John Källén

Reputation: 7943

If you're cleaning up the files with unsorted using statements once (as opposed to having to deal with them on an on-going basis, perhaps because of a sloppy/uncooperative coworker?), and you are willing to use another tool for the job, there is another option.

I like using VS 2005 for its intellisense, but sometimes find the editor lacking in power compared to Emacs. I have Epsilon (an Emacs clone) which has the command sort-region, which takes the lines in the current selection and sorts them alphabetically. I can even type in a keyboard macro in Epsilon that:

  • Finds the first using statement in a file and starts the selection there.
  • Finds the last using statement in the file.
  • Sorts the lines between the first and last using statement.
  • Saves the file.

Upvotes: 1

Related Questions