Visual Studio 代码分析 - Microsoft 自己遵循吗?
进行了快速搜索,但找不到任何与此相关的信息。
我想你们都知道 Visual Studio 代码分析
非常挑剔,并且会针对很多事情发出警告。有谁知道微软自己遵循这一点的情况如何?也就是说,如果我要对它们的程序集运行代码分析,警告是否没有或很少(也许有理由抑制警告......?)。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码分析(或 FXCop)检查的大多数内容都紧密基于“.NET Framework 库设计指南”(书籍,或在 MSDN< /a>)。
然而,这些指南(尤其是书中的指南)有一些警告,并非所有指南都适用于所有情况。
有很多迹象表明微软确实使用了这些工具,但我认为他们确实有理由不像任何其他项目那样始终应用所有规则。
Most of the things that code analysis (or FXCop) check are closely based on the ".NET Framework Library Design Guidelines" (either the book, or on MSDN).
However those guidelines (especially in the book) have caveats, not all apply in all circumstances.
There are plenty of indications that MS do use these tools, but I assume they do have reasons to not apply all the rules all the time, as any other project does.
Microsoft 广泛使用两种核心工具进行代码分析:用于托管代码的 FXCop 和用于本机 C++ 的 PreFast。
从历史上看,虽然并非每个团队在构建产品时都彻底强制使用 CA,但在过去 3-4 年中,特别是现在对其功能团队和其他团队执行相当严格的 CA 要求的团队数量显着增加。产品作为一个整体。
例如,在 Vista 中,Windows 团队基本上停止了 3 个月的产品开发,并对绝大多数关键方法和函数声明进行了 SAL 注释。在Win7中,他们强制要求所有新代码必须符合SAL注释关键场景的一组要求(主要是为了减少缓冲区溢出的可能性)。在 Win8 中,他们更进一步,为许多关键场景合并了新的 SAL 注释。结合改进的编译器和 PreFast 等工具(现已内置于 VS 2010 Pro 及更高版本中),他们和您可以在产品发布之前找到并消除潜在问题。
请注意,CA(无论您选择使用哪个 CA 工具)发出的警告始终需要覆盖 - 有时,有一个很好的理由说明为什么代码必须执行其操作。但只有当您绝对确定这是必要且适当的时,您才应该覆盖。永远不要因为你不理解它而关闭警告,如果你懒得修复它,也永远不要关闭它。
There are two core tools used widely at Microsoft for Code Analysis: FXCop for managed code and PreFast for native C++.
Historically, while not every team has thoroughly enforced the use of CA when building their products, there's been a significant upswing over the last 3-4 years in particular in the number of teams that now enforce pretty stringent CA requirements on their feature teams and on the product as a whole.
For example, in Vista, the Windows team essentially took 3 months off product development and SAL-annotated the vast majority of their key method and function declarations. in Win7, they mandated that all new code had to comply with a set of requirements for SAL-annotating key scenarios (primarily to reduce the likelihood of buffer overruns). In Win8 they're going further still and are incorporating new SAL annotations for a number of key scenarios. Combined with improved compilers and tools like PreFast (now build into VS 2010 Pro and up), they and you can find and eliminate potential issues before the product is released.
Note that the warnings issues by CA (whichever CA tool you choose to use) will always require overrides - sometimes, there's a really good reason as to why the code has to do what it does. But you should only override if you're ABSOLUTELY sure it's necessary and appropriate. NEVER turn off a warning because you don't understand it and never turn off a warning if you can't be bothered to fix it.