问题
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:
- Set the Warning Level to 4 for code analyzers to fire.
- Set rules CS8019 and IDE0005 to warning in your projects' Code Analysis rules (Properties > Code Analysis).
- 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