Figure 143

In fact, the tool doesn't actually look at your source code. Instead, it uses reflection; and once your project has been compiled, it queries the MSIL code your project generates. While this may seem surprising, remember that this tool is looking for several best practices, which may be implemented in different ways in your source code but will always compile in a standard manner.

Figure 1-43 shows the optional Code Analysis screen. Note that even when you have the code analysis tools available, by default, they are not enabled for your project. This is because enabling code analysis significantly extends your compile time. In most cases you'll want to enable these settings for a build or two, and then disable the checks for most of your debug builds. As you can see, to enable analysis you merely check the Enable Code Analysis on Build check box.

Below this check box is a check box to suppress results from generated code. One of the code analysis issues for which Microsoft was criticized after the Visual Studio 2005 release was that if you used the standard project template to create your project and then ran Code Analysis, you would get warnings related to the generated code. Microsoft's solution was to enable you to automatically bypass checking their generated code, which at least enables you to avoid having to manually mark all of the issues related to the generated code as being suppressed.

Once you have enabled the code analysis checks, you also have the option to define exactly which rules you want to apply. The checks are divided into different rule sets. Selecting a rule set such as the Microsoft Minimum Recommended Rules, you can use the Open button to access the display shown in Figure 1-44.

MlnimumRaoommendedRul«.ruloset* 1

▼ □ X

3 Group by;

Cdleyury

O | Isearch P —

,;i> This is a Microsoft rule set and cannot be modified. To create your own rule set based on this rule set make your changes below. Then save your changes to a new file to create the rule set.

* Name

Action

i> ¡V Micro soft Design

Warning

* Micro soft-Glob...

□ Multiple

BMÜCA1301

Avoid duplicate accelerators - C Error

\7CA2101

Specify marshaling for P/Invokc string arguments Jh Warning

l> [^Microsoft-Inter...

Ei Warning

> Micro soft Porta...

¿7-, Wan liny

- [✓ Microsoft Relia...

Ej Warning

i> [¡7 MicrosoftSeeur...

Ej£ Warning

r (v Micro soft. Usage

Warning

Visual Studio can display help for these rules. Do you want to connect to the internet and download help?

Always use online help for rules.

O Never use online help for rules.

© Use online help for ml« one time.

OK

FiGURE 1-44

Within the rule set you see that there is a set of categories, each of which contains one or more rules. When expanded, next to each category and rule is a check box to indicate if that particular rule will be checked. By default, Visual Studio issue warnings if your code fails to meet the requirements associated with a rule. However, you can change the default — for example, by selecting an error status if a given rule fails. This enables you to have some rule violations act as compilation errors instead of warnings. Outside the scope of this chapter is the capability to actually identify within your source code those items that may be flagged by the code analyzer but that are valid exceptions to the rule being checked.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment