Analysis code ensure to follow rules in Developer local computer Visual Studio 2010 and also in your Build server like TFS 2010 . It analyzes managed assemblies and reports information about the assemblies, such as violations of the programming and design rules set . For instance, a classic sample is the correct implementation of a Disposable class which have a IDisposable interface.
Select Code Analysis Settings, the active configuration for each project in the solution will appear.
For each project in a visual studio 2010 solution, we can affect Analysis code rules we want:
Here, we apply all Microsoft rules in the application, and Microsoft Minimum Recommanded Rules in Test projects. You can select different Rules or your custom rules when clicking in Rule Set column as below:
Enable Code Analysis on project properties in order to run Code Analysis on each build
Right click on each project and select properties in the context menu. Check Enable Code Analysis on Build
We can configure rules we want on designer:
It is also possible to select multiple ruleset when choosing <Choose Mutliple rule sets> as follows:
by entreprise analysis code strategy, rules can be set to warning, error or none at rule or category level :
we set Microsoft.Design rule to error at category level:
if a design rule fails, an error occurs instead of a warning
you can save it as your ruleset file (here MyCustomRules.ruleset) – don’t forget to change propertie name in the properties panel of ruleset :
Select browse in Rule set combobox :
when building application (because we have configured Analysis code to run on each build) or if we only run Analysis code by right clicking on project as follows
two error occurs (because of our changes that pass warning design rules to error design rules
if we update Mycustomrule on Design Rules to become warning at category level, we will get only warning, (depending on our entreprise strategy). Below the two design rules appear now as warning :