How to remove unused using namespaces

后端 未结 9 1768
刺人心
刺人心 2020-12-07 22:14

I am using visual studio 2010 and was wondering if there is a way to automatically remove all the namespaces that aren\'t being used at the the top of the page e.g.

相关标签:
9条回答
  • 2020-12-07 23:13

    I know the OP specified VS 2010, but that was a while ago and this feature is built right into VS 2017. From the Menu, Tools -> Options, then find the check box below.

    After that, any time you use CTRL + K , CTRL + D they will be removed.

    0 讨论(0)
  • 2020-12-07 23:17

    In Visual Studio 2017, I use this very simple key combinations: CTRL+R+G to remove unused imports/namespaces

    Update:

    In VS for Mac:

    Unfortunately, there's no default key binding for this but you can always edit your preferences.

    Visual Studio -> Preferences

    In my case, it is binded as +R+G

    0 讨论(0)
  • 2020-12-07 23:18

    I am using Visual Studio 2019 and for some reason my project settings have a Warning level of 3 and this prevent Visual Studio from cleaning the usings. Make sure this value is set to 4.

    Settings -> Build -> Warning Level = 4

    0 讨论(0)
提交回复
热议问题