|
Dev Corner > Blogs > Dev Corner Blog > Posts > Suppressing FxCop
|
e.magination Dev Corner Blog |
|
1/15/2009
FxCop is a great tool for enforcing style rules and best practices. When run as part of an automated build process, these rules are enforced every time the project is compiled. Sometimes it is necessary to break the rules temporarily, such as the case with the rule AvoidNamespacesWithFewTypes which can come up when a developer has begun work in a new namespace, wants to check the code in, but there are very few types contained within because they have not finished adding classes. Rather than turn off the rule, you can create a suppress message and embed it in the code. FxCop will do this for you automatically. When you run FxCop locally, right click on the error message and select "Copy As --> SupressMessage" which will put a piece of code on your clipboard to suppress this message. You will need to define a conditional compilation symbol in the project in order to make the compiler recognize this. To do this, right click on the project and select properties. In the properties tab, select the build tab. In the general section, type CODE_ANALYSIS in the conditional compilation symbols text box. You will also need to import the code analysis namespace, in C# this would be done with "using System.Diagnostics.CodeAnalysis". Then paste in the appropriate piece of code, rebuild, and you are good to go! This is beneficial over suppressing it in the project because it is actually part of the code, and thus not tied to the specific FxCop project. When the rule has been satisfied by further development, this suppress message should be removed. This can be verified during code review by doing a "find in files" and evaluating each suppress message. | Edit in Browser | /_layouts/images/icxddoc.gif | /blogs/DevCorner/_layouts/formserver.aspx?XsnLocation={ItemUrl}&OpenIn=Browser | 0x0 | 0x1 | FileType | xsn | 255 | | Edit in Browser | /_layouts/images/icxddoc.gif | /blogs/DevCorner/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser | 0x0 | 0x1 | ProgId | InfoPath.Document | 255 | | Edit in Browser | /_layouts/images/icxddoc.gif | /blogs/DevCorner/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser | 0x0 | 0x1 | ProgId | InfoPath.Document.2 | 255 | | Edit in Browser | /_layouts/images/icxddoc.gif | /blogs/DevCorner/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser | 0x0 | 0x1 | ProgId | InfoPath.Document.3 | 255 | | Edit in Browser | /_layouts/images/icxddoc.gif | /blogs/DevCorner/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser | 0x0 | 0x1 | ProgId | InfoPath.Document.4 | 255 | | View in Web Browser | /_layouts/images/ichtmxls.gif | /blogs/DevCorner/_layouts/xlviewer.aspx?listguid={ListId}&itemid={ItemId}&DefaultItemOpen=1 | 0x0 | 0x1 | FileType | xlsx | 255 | | View in Web Browser | /_layouts/images/ichtmxls.gif | /blogs/DevCorner/_layouts/xlviewer.aspx?listguid={ListId}&itemid={ItemId}&DefaultItemOpen=1 | 0x0 | 0x1 | FileType | xlsb | 255 | | Snapshot in Excel | /_layouts/images/ewr134.gif | /blogs/DevCorner/_layouts/xlviewer.aspx?listguid={ListId}&itemid={ItemId}&Snapshot=1 | 0x0 | 0x1 | FileType | xlsx | 256 | | Snapshot in Excel | /_layouts/images/ewr134.gif | /blogs/DevCorner/_layouts/xlviewer.aspx?listguid={ListId}&itemid={ItemId}&Snapshot=1 | 0x0 | 0x1 | FileType | xlsb | 256 |
|
|
|
|
|