Update Code Analysis Settings on all Projects
On solutions with many projects (typically, more than 20), it is a rather tedious task to update and keep all the Static Code Analysis settings in Visual Studio the same across all projects. Recently, I found myself faced with the same problem and set out hunting once more.
This time Daniel Fisher (lennybacon) wrote a small macro that can be updated to enable or disable specific rules for Static Code Analysis. This macro is compatible with Visual Studio 2008.
I replicated the macro here for your ease:
Imports System
Imports System.Diagnostics
Imports System.Text
Imports System.Windows.Forms
Imports EnvDTE
Imports EnvDTE80
Public Module CodeAnalysis
Public Sub EnableFxCop()
Dim objProj As Object()
Dim proj As Project
For i As Integer = 1 To DTE.Solution.Projects.Count
proj = DTE.Solution.Projects.Item(i)
EnableFxCop(proj)
Next
End Sub
Private Sub EnableFxCop(ByVal project As Project)
If project.Kind = "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}" Then
'Filter Project Folders
For Each subProject As ProjectItem In project.ProjectItems
EnableFxCop(subProject.SubProject)
Next
Else
project.ConfigurationManager.ActiveConfiguration.Properties.Item( _
"RunCodeAnalysis").Value = "True"
project.ConfigurationManager.ActiveConfiguration.Properties.Item( _
"CodeAnalysisRules").Value = String.Concat( _
"-Microsoft.Design#CA2210;", _
"-Microsoft.Design#CA1020;", _
"-Microsoft.Naming#CA1705;", _
"-Microsoft.Naming#CA1709")
project.Save()
End If
End Sub
End Module
Advertisement

leave a comment