How to Use FxCop

STM32H5 USB虚拟串口:用Classic驱动移植CDC实践 USB虚拟串口(CDC)是嵌入式系统最常用的主机通信方式之一,本质是借助USB协议模拟串口收发,无需额外驱动即可在PC上生成COM口。其实现依赖USB设备协议栈完成枚举、控制传输与批量传输。传统USBD Classic库不依赖RTOS,代码轻量、调用链短,非常适合裸机或轻量状态机架构;而USBX功能强大但需要ThreadX内核,资源开销较大。在电机控制器、传感器采集等场景中,日志输出与参数配置仅需简单的双向数据通道,Classic驱动往往更务实。本文基于STM32H5平台,详细梳理了使用Classic驱动移 阅读详情

来自:http://blog.youkuaiyun.com/yefengmeander/article/details/6572647

As usual there are times when we love cops (when they rescue us from problems). However there are times when we hate say ohh god not cop again (when they catch us or fine).

FxCop.JPG

Introduction

FxCop , an abbreviation "Framework Police," is a rules-based engine that checks managed code assemblies for Microsoft's .NET Framework design guidelines and custom guidelines. FxCop is a rule based engine which helps the development team to follow best practices of the .NET platform and development standards (based on every company standards).
You can apply to any assembly which been created using any language that target Microsoft.NET managed environment.

Why_FxCop.JPG

Answer
  1. Make sure coding standards are followed such as naming conventions, globalization etc. as per company standards.
  2. Avoid bad coding. (No one writes bad code, however as the application grows, development team size also grows usually so every new team member must know how to design their classes, follow naming convention, etc.).
  3. Predefined set of rules.
  4. Support for creating custom rules.
  5. Generate formatted XML Analysis Report.

How_to_use_FxCop.JPG

Once you install FxCop , Go to Start Menu -> All Programs -> "Microsoft FxCop " option and then click on FxCop . It will launch an empty window similar to the one shown below. It contains 3 panes – configuration pane, message pane and properties pane.

Microsoft_FxCop1.JPG

Go to Project Menu and click on “Add Targets…”. Select the EXE or DLL. Once it is done, click on Analyze button and your screen will look like below:

Microsoft_FxCop2.JPG

Configuration Pane

Targets TAB

To analyze and which rules to check load, assemblies/exe. There are 2 tabs at the top of pane (Targets and Rules). It can load more than one assembly into the project by clicking on "Add Target for Analysis" button in toolbar or through Menu "Project->Add Targets”. It shows you all the resources included in the assembly, all the namespaces in the assembly and for each namespace, all the types. Drilling deeper with the plus sign in front of each type, you can show all the members. It shows the constructors, methods, properties and fields.

Selecting a resource, assembly, type or member of a type shows the following information in the property pane:

  • Resource – It lists all the resources and for string resources also displays the string itself.
  • Namespace – Shows the name of the namespace and how many types it contains.
  • Type – Lists a summary about the type which includes the base type, which namespace it is in, its visibility and many more things.
  • Type member – Lists a summary about the type member which includes full name, return type, visibility and more.

Right clicking on a type member, you can select from the "View | IR" popup menu to show the IL code for this member.

Rules TAB

There are by default nine groups of rules:

  1. Design Rules – Rules about the design of your .NET types and assemblies
  2. Globalization Rules – Globalization/localization rules
  3. Interoperability Rules – Rules about COM interoperability
  4. Mobility Rules - Rules about periodic activity that keep the CPU busy
  5. Naming Rules – Rules about naming conventions
  6. Performance Rules – Rules to improve performance of your code
  7. Portability Rules - Rules about portability across different platforms
  8. Security Rules – Rules to make your code more secure
  9. Usage Rules – Rules about proper usage of the .NET Framework

Right click on the rules list displays a popup menu which helps to group the rules in three categories:

  1. File Name – By default grouping and show nine groups of rules
  2. Message Level – Groups the rules by the message level – Critical Error, Error, Critical Warning, Warning and Information. This group provides which rules generate which level of messages.
  3. Breaking Changes – Groups the rules into three groups – Breaking, Non Breaking and Unknown (Default). All rules provided by FxCop are categorized under Breaking or Non-Breaking.

Message Pane

Click on the Analyze button in the toolbar while doing so shows a progress bar, and then fills the message pane with all the messages it found. On top of the pane, you see three buttons – Active, Excluded and Absent.

The Active list shows you all the active messages. These are all the errors and warnings FxCop has found with the last analysis performed. By Default, display four columns in that list:

  • Level – The message level assigns an importance to the message. The following levels are supported:
    1. Critical Error – Issues reported with this level have high visibility and the identified code does not operate correctly in most common scenarios. These issues should be resolved first. You should not exclude issues with this level.
    2. Error – Issues at this level have less visibility and impact. But it still identifies issues in your code you need to resolve. Also these issues should not be excluded without careful consideration.
    3. Critical Warning – This level is mostly used for maintainability issues of your code. The code is working correctly but less-than-optimal. Exclude such messages only after careful consideration.
    4. Warning – Messages with this level are identifying issues in your code around maintainability, extensibility and stability.
    5. Informational – Informational messages about the code.
  • Certainty – Each message has a certainty in percent. A code analysis tool may sometimes not understand completely what you are trying to achieve with your code. So it may report a "false-positive", meaning the tool believes this to be an issue but after you reviewed it, you come to the conclusion that there is nothing wrong with the code. The code does what you intend it to do. Each rule calculates a certainty for each message it generates. This is a way for the rule to tell you how likely this is an issue. You should not exclude messages with a high certainty.
  • Rule – The name of the rule which generated the message.
  • Item – The target item, whether this is the assembly, type or a type member, which generated the message.

    You can right click in the list and select "configure columns" from the popup menu. This allows you to show some additional columns like when was the issue seen first time (Created column), when was the issue seen last time (Last Seen column), is this a new issue (New column), etc.

Selecting a message shows you a summary in the properties pane. It includes the target item which caused the message, a short resolution description and also a help link which shows you a detailed description of the issue and the resolution for it. You can also double click on a message which brings up a dialog box with the same information but differently organized:

Microsoft_FxCop3.JPG

The "Message Details" dialog box has five tabs.

  1. Issues tab - shows you the target item which caused the message. Underneath it you see a list of all messages found for this target item. Clicking on a message in the list will show you in the resolution area below a short description of the resolution. FxCop will also show you a link to the source code if it finds a symbol file (file with the same name as the DLL but with a PDB extension) in the same location where the assembly is located.
  2. Rule Details tab - contains detailed information about the message itself. It shows the message, the message level, the certainty, the description and additional information which helps you to understand what you need to change in your code to resolve the issue.
  3. Message tab - shows you the assembly name which causes the message, when the message appeared the first time and last time plus a tree to the target item, e.g. the method which caused the message.
  4. Rule Support tab - shows you more information about the rule itself. This includes the name of the rule, the URL to the help page associated with the rule, the author of the rule with an email address to contact and information about the assembly which contains the rule.
  5. Notes tab - contains a list of notes you can add to the message. You can add new notes by clicking on the add button, edit existing notes by double clicking on it or remove notes by selecting it and clicking on the remove button. This becomes very useful when you have excluded or resolved a message and you want to go back and find out what you have changed.

You can also filter the messages by clicking on a group of rules, an individual rule or an assembly, namespace, type or type member. Selecting the top node in the Targets or Rule tab shows again all messages. For example, selecting a type allows you to work through all messages of that type. Another example is if you are working on a certain type member, selecting it allows you to view and work through all the messages of this type member. Or maybe you just resolved a certain issue and you want to see any other occurrence of it. So you click on the specific rule which created the message and it allows you to view and work through any other occurrence of that message.

You need to work through all messages one-by-one. A message can describe an issue in your code which needs to be resolved or you determine after careful review that it is a false-positive. If it is a false-positive meaning FxCop believes it to be an issue but you determined after careful review that this is not an issue then you mark it as excluded. You right click on the message and select Exclude from the popup menu. This can also be done by double clicking on the message and clicking on the Exclude button in the "Message Details" dialog. In the upcoming "Edit Notes" dialog box, you enter a summary why it is a false-positive and then click Ok. This moves the message from the Active list to the Excluded list. FxCop will exclude this message from now on every time you perform another analysis. Clicking on the Excluded button on top of the message pane will show you all the excluded messages. Double clicking on the message shows you again the "Message Details" dialog and the Notes tab allows you to view the notes you entered when marking the message as excluded. You can move a message back to the active list by right clicking on it and selecting "Mark as Active" from the popup menu. You can also do this by double clicking on the message and selecting the Unexclude button on the "Message Details" dialog.

You have two ways to remove a message from the Active list after you have resolved the issue. You can right click on the message and select "Mark as Absent" from the popup menu or you just run another analysis and FxCop detects that the issue has been resolved and moves it to the Absent list for you. Don't forget to recompile your code as FxCop doesn't look at the source code but rather the compiled assembly. I consider it good practice to add some notes to the message after it has been moved to the Absent list. This provides a historical view and allows to go back and understand why you have made certain changes. Clicking on the Absent button on top of the message pane shows you all the resolved issues.

Saving your FxCop project only saves active and excluded messages but not the Absent ones. So if you want to keep a historical view go to menu "Project | Options" and on the "Project Options" dialog, on the Standard tab, select the Absent checkbox in the "Save Messages" group. This changes the option only for the current project. Going to "Tools | Settings" menu shows the Settings dialog. On the "Project defaults" tab, select the Absent checkbox under the "Save Messages" group. This setting takes then effect for all future FxCop projects you create. I recommend keeping the historical view because I always find it useful to be able to go back and understand what has been changed on a project over time, especially if you suddenly run into un-explainable exceptions, crashes or other difficulties with your product.

Properties Pane

This pane has two tabs. The properties tab shows information about the selected assembly, namespace, type, type member, group of rules, rule or message. We have covered that already in detail. The Output tab shows informational, warning and error messages generated by the rules. These messages only appear if the TraceGeneral trace-switch in the FxCop .exe .config file is enabled.

Reporting Features

Click on the menu "File | Save Report As" and provide a name and location for the report. The report is stored as an XML document which references a XSLT document - FxCop Report.xsl . Opening the report with your browser uses the referenced XSLT document to render a HTML report. The report allows you to drill down to all messages on the assembly level, type level and type member level.

The report, by default, only includes active messages. So, if you want to keep a historical view, go to menu "Project | Options" and on the "Project Options" dialog, on the Standard tab, select the Excluded and Absent checkbox in the "Save Messages" group (for reporting). This changes the option only for the current project. Going to "Tools | Settings" menu shows the Settings dialog. On the "Project defaults" tab, select the Excluded and Absent checkbox under the "Save Messages" group (for reporting). This setting then takes effect for all future FxCop projects you create. Try to include the historical view in the generated reports because it is useful to be able to go back and understand what has been changed on a project over time.

Microsoft_FxCop4.JPG - click to enlarge image

Visual Studio Integration of FxCop

To set up FxCop as an external tool in Visual Studio:

  1. On the Tools menu, click External Tools, and then click Add.
  2. Enter the following information in External Tools dialog box:
    • Title: FxCop
    • Command: C:/Program Files/Microsoft FxCop 1.36/FxCop Cmd.exe
    • Arguments: /c /f:$(TargetPath) /d:$(BinDir) /r:"c:/Program Files/Microsoft FxCop 1.36/Rules"
    • Initial directory: C:/Program Files/Microsoft FxCop 1.36

Note : If you had created custom rules and want to apply to all projects, place the custom rule DLL to c:/Program Files/Microsoft FxCop 1.36/Rules .

The External Tools configuration dialog box is displayed. The following screen shot shows the dialog box after the steps in this procedure have been completed.

Microsoft_FxCop5.JPG

Done. Now you just need to run FxCop .
Go to Tools –> FxCop analyze your code and because we checked “Use Output window” in External Tools dialog, result should appear in Visual Studio output window.

FxCop_Limitation.JPG

  1. Works with any managed assembly created in .NET language that run on Microsoft .NET Framework.
  2. It cannot automatically fix errors if it finds.
  3. Currently supports only one type of report. No support for custom type report.

FxCop_Vs_StyleCop_Vs_Code_Analysis.JPG

FxCop
  1. It runs on compiled DLLs.
  2. As it runs on compiled IL code, it can be used for C#, VB.NET, in short any language which compiles to IL code.
StyleCop
  1. Keep in mind that it is not a Microsoft product. It is not even a Team System Power Tool. It is a tool developed by a very passionate developer at Microsoft (on evenings and weekends). There's no support, servicing, evolution or anything else beyond what he can get done in his spare time. Style checking is an interesting feature and may show up in an official product at some point down the road.
  2. It runs on actual source code.
  3. Currently it runs only on C#.
  4. The ultimate goal of StyleCop is to allow to produce elegant, consistent code that team members and others who view developer code will find highly readable.
Code Analysis
  1. No spell checking - FxCop uses a dictionary (plus custom dictionary) to check the names of methods, classes, etc. Code Analysis doesn't seem to do that.
  2. Help - FxCop not only complained when something was wrong but provided a great deal of help/hints to resolve the problem. Code Analysis just seems to present the problem with no sign of a hint.
  3. Note that Code Analysis is only available in the Premium and Ultimate editions of Visual Studio 2010 and also Visual Studio 2005 & 2008 Team System.

Area Not Covered for FxCop

  1. Webservices/WCF
  2. Validate XML Document

Further Reading


Autodesk Genuine Service卸载失败?试试这个隐藏文件删除法(Win8-Win11通用) 本文针对Autodesk Genuine Service在Windows系统(Win8-Win11)中卸载失败的常见难题,提供了深度解析与根治方案。核心方法是手动定位并删除两个关键的隐藏文件(ProductInformation.pit和id.dat),以解除文件锁定或数据损坏导致的卸载障碍,随后再通过标准流程即可成功卸载。该方法通用性强,能有效解决这一困扰设计师和工程师的顽固问题。 阅读详情

相关推荐

告别混乱!用Cadence Capture CIS高效管理你的原理图库:以单逻辑器件K9F2G08U0M为例

本文以单逻辑器件K9F2G08U0M为例,详细介绍了如何使用Cadence Capture CIS高效管理原理图库。通过三级分类体系、工程化命名规范和智能检索技术,帮助工程师实现从混乱到有序的转变,提升团队协作效率和设计准确性。

aizhi0169的博客 398

java编程中易犯的十个错误[英文]

(How to spot them. How to fix/prevent them.)By David ReillyWhether you program regularly in Java, and know it like the back of your hand, or whether youre new to the language or a casual programmer,

年轻无极限 2587

SNAP计算哨兵二号的叶面积指数(LAI)

对于哨兵二号数据以及LANDSAT8数据,SNAP提供已经集成好的模块计算LAI。在Optical->Thematic Land Processing->Biopyhsical Processor目录下面。 对于经过Sen2Cor处理好的数据,需经过重采样才可进行计算。重采样工具在Raster->Geometric->Resampling。 如果选择Biopyhsical Processor S2_10m进行计算,需要将所有的波段都重采样为10米(哨兵二号的第二波段为10米,可据此波

gxwwww的博客 9414

FxCop to the Rescue(reship)

Bad Code? FxCop to the Rescue SourcePageFrom : http://msdn.microsoft.com/msdnmag/issues/04/06/bugslayer/ John Robbins Download the code for this article: Bugslayer0406.exe (1...

LEWENCAI560618的博客 370

望获实时Linux与国产芯片协同:打造LinuxCNC数控机床的全栈国产化方案

本文探讨了如何通过望获实时Linux与飞腾、龙芯等国产芯片的深度协同,为LinuxCNC数控机床打造全栈国产化方案。望获实时Linux通过中断隔离等核心技术,提供亚微秒级确定性响应,解决了传统Linux系统实时性不足的痛点,使LinuxCNC得以稳定驱动高精度机床。该方案实现了从硬件、操作系统到应用软件的全栈自主可控,为工业控制领域提供了高性能、可定制的国产化选择。

weixin_29291069的博客 647

逻辑回归:利用Python实现二分类算法

通过使用Python编写的代码,我们可以训练逻辑回归模型并进行预测。接下来,我们将实现逻辑回归算法的训练函数。训练函数将接受训练数据集X和对应的标签y,以及学习率alpha和迭代次数num_iterations。训练完成后,我们可以使用训练得到的参数theta来进行预测。在这个例子中,我们有一个包含4个样本的训练数据集X,每个样本有两个特征。在这个例子中,如果预测概率大于等于0.5,则预测为类别1,否则预测为类别0。现在,我们可以使用训练函数来训练模型。根据给定的样本x_new,预测函数将返回相应的类别。

XlltEditor的博客 326

FxCop 和 StyleCop 的关系

参考: StyleCop vs FxCop C# Code Reviews using StyleCop - Detailed Article How to Use FxCop FxCop Warnings StyleCop Rules 7 Steps to Write Your Own Custom Rule using FxCop FxCop 检测的是编译后的程序集。所以有些

一个被IT搞的 1074

探索 .NET 多版本兼容的精美 WinForms UI 控件库:ReaLTaiizor

你可以根据需要修改主题的颜色方案。// 示例:修改主题颜色设置主色和次色。应用到中。通过继承和重写控件的方法,可以实现自定义样式。// 示例:自定义 MetroButton 样式// 自定义绘制逻辑创建类继承自。重写OnPaint方法,添加自定义绘制逻辑。

墨夶的博客 1508

FxCop vs StyleCop vs Code Analysis

Here I'm going to clarify the difference between FxCop and StyleCop and Analysis. The main reason I'm writing this post is to give a professional answer to the question about the relationship of the a...

weixin_30932215的博客 89

SOME/IP协议详解「1.1·面向服务与面向信号」

面向信号和面向服务的区别,和举例子

雪云飞星的博客 5652

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

[FxCop.设计规则]12. 不要捕获所有异常

12. 不要捕获所有异常 翻译概述: 在传统的C++中,对于大多数错误逻辑使用返回错误码的方式来定义。从而使程序逻辑中充斥了大量的条件判断逻辑,严重的影响了代码的可维护性和美观。而异常机制为开发提供了一套相对独立和易管理的错误处理方式,因此,在目前的大多数程序设计语言中都提供了对异常的支持,包括C++。 但是,异常属于一个脱离程序逻辑之外的控制流程,因此,对异常的滥用很多时候反而会降...

weixin_30394333的博客 112

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

How to write custom static code analysis rules and integrate them into Visual Studio 2010

How to write custom static code analysis rules and integrate them into Visual Studio 2010 RATE THIS Duke Kamstra  26 Mar 2010 4:58 PM  5 This blog explains how to impl

riverlau的专栏 1497

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

[FxCop.设计规则]6. 避免使用输出参数

6.     避免使用输出参数原文引用:Avoid out parametersTypeName:AvoidOutParametersCheckId:CA1021Category:Microsoft.DesignMessage Level:WarningCertainty:50% Breaking Change:BreakingCause: A public or protected method

cajon的专栏 1424

How to write the fast code/ high performance in C#

Performance Techniques for C# 4.0 Anthony Moore Contents Contents.1 Overview..1 Patterns by Construct.1 Cheat Sheet.1 Collection Interfaces (IEnumerable,ICollection, IList).2 Internal and Se

kielin的专栏 1209

CruiseControl.Net Setup Constructions,CruiseControl.Net安装流程(NUnit+FxCop+NCover+NDoc+Fitness)

  CruiseControl Setup Constructions Server side configurationSystem requireIIS and .Net Framework 2.0, source control server (svn) at some where1 setup CruiseControl Just click next, n

siao's BG4 2174

Effective C#之Item 48:Learn About Tools and Resources

 v/:* {behavior:url(#default#VML);}o/:* {behavior:url(#default#VML);}w/:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);} Normal 0 7.8 磅 0

一路采撷 1303

[FxCop.设计规则]2. 程序集应该拥有有效的强命名

  版权声明:   本文由timewolf完成,首发于优快云,作者保留版权。未经许可,不得使用于任何商业用途。欢迎转载,但请保持文章及版权声明完整。如需联络请发邮件:karla9(AT)eyou(dot)com

timewolf的专栏 1344
上一篇: SAF 中抽象工厂的实现(Remoting的实体统一由服务器端实现)
下一篇: javascript技巧 200多个
ArvinStudy
博客等级 码龄15年 83粉丝 193原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值