简体   繁体   English

如何关闭灰色未使用的用途?

[英]How to turn off graying out unused usings?

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) ?? 如何(假设甚至可能)关闭Visual Studio 2015功能以清除未使用的使用(在C#中使用,在VB中导入)? I like all the other highlight / syntax checking / auto compile stuff in VS, I'm only trying to turn this off specifically to graying out unused usings. 我喜欢VS中的所有其他突出显示/语法检查/自动编译内容,我只是试图将其关闭以专门用于灰化未使用的使用。

I can't seem to find an option for this specifically in the VS 2015 menus. 我似乎无法在VS 2015菜单中找到这个选项。 If anybody is aware of such an option please advise as to location. 如果有人知道这样的选择,请告知位置。

You can disable it on a project-by-project basis. 您可以逐个项目地禁用它。 Open your project references > Analyzers and turn off IDE0005 . 打开项目参考>分析器并关闭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). 不要认为有可能禁用它(你真的不应该这样做)。

在此输入图像描述


在此输入图像描述

If the unused using is actually useful (ie shortens names of types in documentation comments when you pause your mouse over a member outside debug mode). 如果未using实际上是有用的(例如,当您将鼠标悬停在调试模式之外的成员上时缩短文档注释中的类型名称)。 You can suppress the warning for those usings with #pragma warning disable : 您可以使用#pragma warning disable那些使用#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

#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. 请注意,从VS 2017 15.6.6开始, Remove and Sort Usings的菜单选项将忽略#pragma warning disable指令。 As I think this is a bug, I will be submitting a roslyn issue. 我认为这是一个错误,我将提交一个roslyn问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM