Code Analysis Properties for C/C++

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 Page

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

Project Configuration and Platform

The Configuration list and 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

You can select whether to enable Code Analysis for your project by setting Enable Code Analysis For C/C++ on Build to Yes (\analyze). In combination with the Configuration list, you could, for example, decide to disable Code Analysis for debug builds and enable it for release builds.

If your project contains managed code, you can decide whether to enable or disable Code Analysis by setting Enable Code Analysis For Managed Binaries on Build to Yes.

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

Developers often use third-party tools to help develop applications quickly. These tools often 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 do not want to maintain the code.

The Suppress Results From Generated Code check box on the General properties page enables you to select whether you want to see Code Analysis warnings from code generated by a third-party tool.

Rule Settings

The Managed Code Analysis Rules property page contains a view of the managed code rules by category. You can expand each category to view the rules in it. 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 about Code Analysis rules for native code, see Code Analysis for C/C++ Warnings.

See Also

Concepts

Code Analysis Properties for Managed Code

Other Resources

Code Analysis for C/C++ Warnings