Code Analysis Properties for Managed Code

You can configure which rules Code Analysis uses to analyze the code in each configuration of your project. In addition, you can direct Code Analysis to suppress warnings from code that was generated and added to your project by a third-party tool.

Code Analysis Property Tab

The Code Analysis property tab contains all Code Analysis configuration settings for a project. To open the Code Analysis property tab for a project in Solution Explorer, right-click the project and click Properties. Select the Code Analysis tab.

Note

The Code Analysis property tab is not applicable for a Web site project. However, you can modify code analysis configuration for Web site projects by going to the Analyze menu and clicking Code Analysis Configuration.

Project Configuration and Platform

The Configuration list and the Platform list enable you to apply different Code Analysis settings to different project configuration and platform combinations. For example, you can direct Code Analysis to apply one set of rules to your project for debug builds and a different set for release builds.

Enabling Code Analysis

The Enable Code Analysis (defines CODE_ANALYSIS constant) check box enables you to select whether to enable Code Analysis for your project or disable it all together. In combination with the Configuration list, you could, for example, decide to disable Code Analysis for debug builds and enable it for release builds.

Code Analysis is designed to help you improve the quality of your code and avoid common pitfalls. Therefore, consider carefully whether to disable Code Analysis. It is usually better to disable rule categories or individual rules that you do not want applied to your project.

Generated Code

Managed code compilers often generate code that is added to a project to facilitate rapid code development. In addition, developers often use third-party tools to help develop applications quickly. These tools also generate code that is added to the project.

You might want to see the rule violations that Code Analysis discovers in generated code. However, you might not want to see them if you cannot view and maintain the code that contains the violation.

The Suppress results from generated code check box enables you to select whether you want to see Code Analysis warnings from code generated by a third-party tool.

Note

This option does not suppress Code Analysis errors and warnings from generated code when the errors and warnings appear in forms and templates. You are able to both view and maintain the source code for a form or a template.

However, if you are working in a Web site project, the Suppress results from generated code check box is not applicable.

Rule Settings

The Code Analysis property tab contains a view of the rule categories that you can expand to view the rules under each category. If the check box next to a rule contains a check mark, that rule is enabled. You can enable or disable all the rules in a category by selecting or clearing the check box next to the category name.

By default, violations of Code Analysis rules are displayed in the Visual Studio Error List as warnings. You can decide individually to display them as errors by selecting the Treat Warning as Error check box associated with the rule or rule category.

For information more information about rule categories and the rules they contain, see Code Analysis for Managed Code Warnings.

See Also

Concepts

Code Analysis Properties for C/C++

Other Resources

Code Analysis for Managed Code Warnings