How to turn off graying out unused usings?

后端 未结 2 1056
一个人的身影
一个人的身影 2021-01-12 07:02

How (supposing it\'s even possible) to turn off the Visual Studio 2015 feature to gray out unused usings (usings in C#, Imports in VB) ?? I like all the other highlight / s

相关标签:
2条回答
  • 2021-01-12 07:40

    You can disable it on a project-by-project basis. Open your project references > Analyzers and turn off IDE0005. This will disable the 'visual cue' (grayed out hint) but you will still be able to select the quick action 'Remove unnecessary usings' if you put the cursor on one of these. Don't think it's possible to disable this (and you really shouldn't anyway).


    0 讨论(0)
  • 2021-01-12 07:49

    If the unused using is actually useful (i.e. shortens names of types in documentation comments when you pause your mouse over a member outside debug mode). You can suppress the warning for those usings with #pragma warning disable:

    #pragma warning disable IDE0005 // Using directive is unnecessary
    

    To resume the behavior in the file, you would use #pragma warning restore.

    #pragma warning restore IDE0005 // Using directive is unnecessary
    

    Do be warned, as of VS 2017 15.6.6, the menu option for Remove and Sort Usings will ignore the #pragma warning disable directives. As I think this is a bug, I will be submitting a roslyn issue.

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