I know you can do it file by file.
Is there any way to do this in one step for all files in a project?
Here's a small improvement on the script above for VB.NET. Make sure you have the Productivity Power Tools installed.
Private Sub RemoveAndSortSome(ByVal projectItem As ProjectItem)
On Error Resume Next
If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then
If projectItem.Name.LastIndexOf(".cs") = projectItem.Name.Length - 3 Then
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("Edit.RemoveAndSort")
window.Close(vsSaveChanges.vsSaveChangesYes)
ElseIf projectItem.Name.LastIndexOf(".vb") = projectItem.Name.Length - 3 Then
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("EditorContextMenus.CodeWindow.OrganizeImports.RemoveandSortImports")
window.Close(vsSaveChanges.vsSaveChangesYes)
End If
End I