What is the static analysis rule to warn about unused using statements?

强颜欢笑 提交于 2021-02-09 07:13:24

问题


Is there any FxCop or StyleCop that warns when there is an using statement that is no longer referenced by any object in the file?


回答1:


You can enable the rule IDE0005 C# Using directive is unnecessary. in the category Style.




回答2:


In addition to Udo's answer and this answer, I also needed to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses.

So all in all:

  1. Set the Warning Level to 4 for code analyzers to fire.
  2. Set rules CS8019 and IDE0005 to warning in your projects' Code Analysis rules (Properties > Code Analysis).
  3. Make sure to uncheck Suppress results from generated code (managed only) which can be found under Properties > Code Analyses.


来源:https://stackoverflow.com/questions/39043332/what-is-the-static-analysis-rule-to-warn-about-unused-using-statements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!