9.5 Writing Better Code with FxCop

Every high-quality application conforms to a certain set of predefined coding standards and design guidelines. This helps to ensure consistency within the application’s code base, which in turn simplifies code maintenance and the addition of new functionality.

To ease the enforcement of coding standards and design guidelines, Microsoft has developed a free static code analysis tool named FxCop, which analyzes .NET assemblies for conformance to the Microsoft .NET Framework Design Guidelines (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnet-frameworkdesignguidelines.asp). The tool uses reflection, Microsoft Intermediate Language (MSIL) parsing, and call-graph analysis to inspect assemblies for defects in the following areas:

  • Library design

  • Localization

  • Naming conventions

  • Performance

  • Security

Although primarily targeted at class-library developers, FxCop can be used on any managed code assembly written in any .NET language. FxCop includes both a GUI and command-line version, as well as an SDK to create your own custom analysis rules. The command-line version of FxCop is especially handy when used in a continuous integration process with a tool like CruiseControl.NET (see Chapter 12).

One interesting aspect of using FxCop is that it can be used as a learning tool, especially with regard to overall design guidelines and best practices. So, even if you don’t use FxCop to strictly enforce certain standards and guidelines, ...

Get Windows Developer Power Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.