Secondly, removing unused “Using” is gives fellow programmers sifting through your code a reasonable idea of the purpose of your application. If however you scatter your “Using” section with unnecessary packages, you will give your application in essence a false identity.
However, including unnecessary “Using” will NOT cause a performance difference in compiled languages during runtime. It may however cause the complication to be a second longer, but in this day an age, that is not a problem.
Finally (#3), removing your unused “Using” only takes only a second in Visual Studio. All you need to do is right click in your codebehind file. Go to Organize Usings, and select “Remove Unused Usings”. A better option is to click “Remove and Sort”, to give me a more organized list.
Now An Important question : "How do I remove all Unused Usings from all the class files in my Project, if I have more than 200 class files? Do I need to open all the files and remove all Unused as mentioned above manually for all files?"
If this is your question, then here is a simple answer and an easy solution:
1) Open your Visual Studio
2) Open Tools Menu -> Macros -> Macro Explorer (Keyboard ShortCut : Alt + F8)
3) Right Click on MyMacros -> Select New Module
4) After creating new module Replace all default generated code with below code:
Public Module mdlRemoveAndSortAll
Public Sub RemoveAndSortAll()
On Error Resume Next
Dim sol As Solution = DTE.Solution
For i As Integer = 1 To sol.Projects.Count
Dim proj As Project = sol.Projects.Item(i)
For j As Integer = 1 To proj.ProjectItems.Count
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)
For i As Integer = 1 To projectItem.ProjectItems.Count
5) Save it and Close the editor.
Congrats, You have created a Custom Macro in MS Visual Studio.
Now to use it :
1) Open your solution
2) Select your macro from Macro Explorer window
3) Right Click -> Run
Wait and watch..... All the Unused Usings from all the Class files in your entire solution will be removed.. Enjoy..
If you like this post, please +1 this post from below toolbar, you can also place a comment or vote below.