vb.net 找到“死代码”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38658555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:00:11  来源:igfitidea点击:

Find "Dead code"

c#vb.netvisual-studio-2012code-analysis

提问by Rubén Aroca

I am trying to find private methods that are not called from any other code (CA1811) https://msdn.microsoft.com/en-us/library/ms182264(v=vs.110).aspx, with Visual Studio 2012 Code Analysis buy it doesn't detect it, despite putting the project code analysis rule set in "all rules". This is possible? In this case, how can I configure my project solution? In case of installing any extension, I will prefer that it was free. Thanks!

我正在尝试使用 Visual Studio 2012 代码查找未从任何其他代码 (CA1811) https://msdn.microsoft.com/en-us/library/ms182264(v=vs.110).aspx调用的私有方法尽管将项目代码分析规则集放在“所有规则”中,但分析购买它并没有检测到它。这个有可能?在这种情况下,我该如何配置我的项目解决方案?在安装任何扩展的情况下,我更喜欢它是免费的。谢谢!

回答by Jan De Dobbeleer

In case you are OK with a command line utility, I suggest the Resharper Command Line tool. It can do many great things that will help you, including finding dead code. It's free (Resharper VS extension is not) so it will get you going.

如果您对命令行实用程序没问题,我建议使用Resharper 命令行工具。它可以做很多对你有帮助的伟大事情,包括查找死代码。它是免费的(Resharper VS 扩展不是)所以它会让你继续前进。

If Resharper can't find any dead code, maybe there's none and Code Analysis does work :-)

如果 Resharper 找不到任何死代码,也许没有,代码分析确实有效:-)

回答by Yogi

The rule CA1811: Avoid uncalled private codeperfectly works fine to detect the uncalled private methods.

规则CA1811:避免未调用的私有代码可以很好地检测未调用的私有方法。

To enable the code analysis warnings, you also need to set this value in project properties like this -

要启用代码分析警告,您还需要在项目属性中设置此值,如下所示 -

enter image description here

在此处输入图片说明

As a suggestion it is good idea to have our custom ruleset, to have more control over rule violations for example you can define any violation as error, so that you can get it as compile error and fix it.

作为一个建议,拥有我们的自定义规则集是个好主意,为了更好地控制规则违规,例如您可以将任何违规定义为错误,以便您可以将其作为编译错误并修复它。