FAQ: How do I share Managed Code Analysis rule settings over multiple projects? [David Kean]
If your team has a minbar of Managed Code Analysis rules that must be explicitly fixed or suppressed, it is possible to share the Managed Code Analysis rule settings over multiple MSBuild projects (.csproj, .vbproj).
To share the minbar between multiple projects, do the following:
Using Visual Studio, create a new empty project
In Solution Explorer, right-click the project and choose Properties
In the Project Properties window, choose the Code Analysis tab
In the Code Analysis tab, choose the rules you want for your minbar
In Solution Explorer, right-click the project and choose Unload Project, answering Yes to any prompt to save changes
In Solution Explorer, right-click the project and choose Edit
Search for the <CodeAnalysisRules> element and copy the text within it
Create an empty text file called [team].CodeAnalysis.Rules.targets, replacing [team] with the name of your team
In the text file enter the following, replacing [rulesettings] with the text copied above in Step 6:
<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <CodeAnalysisRules>$(CodeAnalysisRules); [rulesettings]< /CodeAnalysisRules> </PropertyGroup> </Project>
If you do not want developers to be able to turn on extra rules over and above the minbar, do not add the ' $(CodeAnalysisRules); ' text.
Using Visual Studio, open your projects
In Solution Explorer, right-click a project and choose Unload Project
In Solution Explorer, right-click the unloaded project and choose Edit
Add the following <Import> element to the project, replacing [path] with the path of the targets file created above. This needs to be the last line (just above the closing </Project> element) to ensure that settings within the project do not override the team settings:
<Project DefaultTargets="Build" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
[...]
<ImportProject=" [path] " /> </Project>
Repeat from Step 11 for each project you want to share the rule settings with
Any projects that imported the common rule settings via Step 9, should now reflect these settings in the Code Analysis properties pane. You can also share any MSBuild properties using similar steps.
Please Note: In order to avoid Visual Studio prompting about unsafe imported MSBuild projects, you need to explicitly trust the [team].CodeAnalysis.Rules.targets file. To do this, use the following:
- Run regedit
- Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\MSBuild\SafeImports
- Add a new string value called [team].CodeAnalysis.Rules.targets and set its value to the full path of the targets file.
Comments
Anonymous
January 07, 2007
I've noticed that Code Analysis sometimes places suppressions in a file called GlobalSuppression.cs (GlobalSuppressions.vbAnonymous
May 15, 2007
A while ago I mentioned that FxCop (and hence Managed Code Analysis) naming and design rules only fireAnonymous
August 08, 2007
For Visual Studio 2008, we have added a new MSBuild property that allows you to easily treat all CodeAnonymous
August 22, 2007
Al fin!!!!!!!!, algo que ya había comentado como parte de mi participación en el TAP de Orcas, es laAnonymous
August 22, 2007
Once you turn on the new spelling rules that we've added to Visual Studio 2008, you will want to startAnonymous
August 22, 2007
Al fin!!!!!!!!, algo que ya había comentado como parte de mi participación en el TAP de Orcas, es laAnonymous
August 31, 2007
After searching a bit, I found a way to disable specific Code Analysis rules for a team build. Or at