2009-07-10 44 views
3

有沒有人寫過一個宏,將刪除和排序整個項目中的使用情況?我希望在沒有像ReSharper這樣的第三方加載項的情況下完成此操作。項目範圍「刪除和排序使用」

+0

的[可能重複反正是有跨越整個項目中刪除未使用的命名空間或解決方案](http://stackoverflow.com/questions/283471/is-there-anyway-to-remove-unused-namespaces-across-a-whole-project-or-solution-a) – Larry 2013-03-15 19:28:06

回答

3

如果您會考慮使用Microsoft加載項,您會發現Power Commands實用程序將爲項目或解決方案執行此操作。

更新:我知道我有一點是做了一件這樣的代碼,我發現了它,並在這裏它是:

Imports System 
Imports EnvDTE 
Imports EnvDTE80 
Imports EnvDTE90 
Imports System.Diagnostics 

Public Module FormatDocuments 

    Public Sub FormatSolution() 

     Dim sol As Solution = DTE.Solution 

     For i As Integer = 1 To sol.Projects.Count 

      FormatProject(sol.Projects.Item(i)) 

     Next 


    End Sub 

    Private Sub FormatProject(ByVal proj As Project) 
     For i As Integer = 1 To proj.ProjectItems.Count 

      FormatProjectItem(proj.ProjectItems.Item(i)) 

     Next 


    End Sub 

    Private Sub FormatProjectItem(ByVal projectItem As ProjectItem) 

     If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then 

      If projectItem.Name.EndsWith(".cs") Then 

       Dim window As Window = projectItem.Open(Constants.vsViewKindCode) 

       window.Activate() 

       projectItem.Document.DTE.ExecuteCommand("Edit.RemoveAndSort") 

       window.Close(vsSaveChanges.vsSaveChangesYes) 

      End If 
     End If 

     If projectItem.ProjectItems.Count > 0 Then 
      For Each subProjectItem As ProjectItem In projectItem.ProjectItems 
       FormatProjectItem(subProjectItem) 
      Next 
     End If 
    End Sub 


End Module 
+0

問題我與ReSharper或另一個(我現在忘記名稱)是(根據我的經驗)IDE顯着下降。你有沒有注意到powercommands這樣做? – Joe 2009-07-10 01:14:14