Share via


Code Analysis for Managed Code Overview

Code analysis for managed code tool analyzes managed assemblies and reports information about the assemblies, such as violations of the programming and design rules set forth in the Microsoft .NET Framework Design Guidelines.

The analysis tool represents the checks it performs during an analysis as warnings. Warning messages identify any relevant programming and design issues and, when possible, supply information about how to fix the problem.

  • IDE (integrated development environment) Integration

    To make it convenient for developers to use the analysis tool, developers can select Enable Code Analysis on the project's Property Pages.

    Additional options for including or excluding rules and treating rules as warnings or errors can also be accessed from property pages. When the tool is enabled, during the build process, it reports warnings in the Error List.

  • In Source Suppression

    It is often useful to indicate that a warning is non-applicable; this informs the developer, and others who might review the code later, that a warning was investigated and then either suppressed or ignored.

    In Source Suppression of warnings is implemented through custom attributes. To suppress a warning, add the attribute SuppressMessage to the source code as shown in the following example:

    [SuppressMessage("AdventureWorks.Rules", "AW14441")]

    Public class MyClass

    {

    // code

    }

    For more information, see Suppress Warnings Using SuppressMessage Attribute.

  • Run code analysis tool as part of check-in policy

    As an organization, you might want to require that all check-ins satisfy certain policies. In particular, you want to make sure that you follow these policies:

    • There were no build errors in code being checked in.

    • Code analysis was run as part of the most recent build.

    You can accomplish this by specifying check-in policies. For more information, see How to: Add Check-in Policies.

  • Team System Team Build Integration

    You can use the integrated features of the build system to run the analysis tool as part of the build process. For more information, see Overview of Team Foundation Build.

See Also

Tasks

How to: Enable and Disable Code Analysis for Managed Code