55.2. Managed Code Analysis Tool

This is a tool based on FxCop, a Microsoft internal tool, released to the public a few years ago and finally integrated into the IDE. It will allow you to perform static code analysis using a set of rules. You can activate it from the project's property window as shown in Figure 55-2.

To use it you can right-click a project and select Run Code Analysis, or if you selected Enable Code Analysis on Build in the project's property window, you can simply compile it. The rules will be evaluated and if there is any violation (and believe me, there will be sooner or later) you will have a set of warnings in the Error List window. By default each violation will appear as a warning, but you can change this behavior by selecting Treat Warning as Error.

If you right-click a warning and select Show Error Help, you will have a description of the rule, the cause, steps on how to fix violations, and suggestions on when to suppress warnings.

You have more than 200 rules conveniently organized in 11 categories, and you can add custom rules if needed. Depending on your project, you might want to exclude some categories or some particular rules. For example, if you don't need globalization and don't have plans in the future to support it, you might exclude that category. Another option is to suppress a particular warning by right-clicking it in the Errors window.

Figure 55.2. Figure 55-2

I recommend starting with all the rules activated and excluding them or suppressing ...

Get Professional Visual Studio® 2008 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.