While dealing with maintaining coding standard like stylecop warning fix with code, most of the time we need to remove unused namespaces and sort the namespaces. We can do it easily from the context menu of the code editor. There you have three different option for “Organize Using” . Either you can Remove Unused Usings , Sort Usings or we can do it together by selecting “Remove and Sort” . Let’s see how we can make it more handy !
Even we can automatically fix this using some third party tools and addins. But it can be even very handy with in visual studio aswell, if we can set some shortcut key for them. From Tools > Option, navigate to Keyboard tab. Search for “Edit.RemoveAndSort” which command will to both remove unused usings and sort the usings, then set shortcut for the same, as I did with “Ctrl + Shift + W” , Click on “Assign” and Ok. you are done.
From next time you just need to press “Ctrl+Shift+W” to remove unused namespaces and sort them accordingly.
Even you can set the same for “Sort Usings” ( “Edit.SortUsings” ) and “Removed Unused Usings” (“Edit.RemoveUsings”) .
Hope this will help save some of your time !
Thanks !
AJ
thanks man…
LikeLike
Thanks, very usefull 😉
LikeLike
Thanks for this. Very helpful to men! 🙂
LikeLike
Really helpful. Thanks!
LikeLike
Thanks. Very helpful (i assigne CTRL+Shift+O to remind me of eclipse shortcut ‘remove unused imports’)
LikeLike
Thank you very much, Abhijit! Very helpful tip.
LikeLike
Thanks mate. You can check out my another site for .NET tips and tricks http://dailydotnettips.com/
LikeLike
Thank you a lot, Abhijit! This tip will really speed up my work using Visual Studio!
LikeLike
Cheers !!
LikeLike
There you very much! Awesome tip!
LikeLike
You may check out – https://dailydotnettips.com for more Tips and Tricks on .NET
LikeLike