Welcome to MSDN Blogs Sign in | Join | Help

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:

  1. Using Visual Studio, create a new empty project
  2. In Solution Explorer, right-click the project and choose Properties
  3. In the Project Properties window, choose the Code Analysis tab
  4. In the Code Analysis tab, choose the rules you want for your minbar
  5. In Solution Explorer, right-click the project and choose Unload Project, answering Yes to any prompt to save changes
  6. In Solution Explorer, right-click the project and choose Edit
  7. Search for the <CodeAnalysisRules> element and copy the text within it
  8. Create an empty text file called [team].CodeAnalysis.Rules.targets, replacing [team] with the name of your team
  9. In the text file enter the following, replacing [rulesettings] with the text copied above in Step 6:

     <Project xmlns="http://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.

  10. Using Visual Studio, open your projects
  11. In Solution Explorer, right-click a project and choose Unload Project
  12. In Solution Explorer, right-click the unloaded project and choose Edit
  13. 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="http://schemas.microsoft.com/developer/msbuild/2003"

       [...]

       <Import Project="[path]" />
     </
    Project>


  14. 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:

  1. Run regedit
  2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\MSBuild\SafeImports
  3. Add a new string value called [team].CodeAnalysis.Rules.targets and set its value to the full path of the targets file.
Published Thursday, November 16, 2006 9:51 AM by David M. Kean

Comments

Sunday, January 07, 2007 12:56 PM by Visual Studio Managed Code Analysis (FxCop)

# FAQ: What is the GlobalSuppressions.cs/GlobalSuppressions.vb file and why is it needed? Is it possible to change the name of this file? [David Kean]

I've noticed that Code Analysis sometimes places suppressions in a file called GlobalSuppression.cs (GlobalSuppressions.vb

Tuesday, February 13, 2007 4:52 PM by Tim McCarthy's Blog

# How to Create Custom Code Analysis Rules for VSTS 2005

Wednesday, February 14, 2007 2:21 AM by Tim McCarthy's Blog

# How to Create Custom Code Analysis Rules for VSTS 2005

Tuesday, May 15, 2007 10:47 AM by The Visual Studio Code Analysis Team Blog

# TIP: How to change the (Orcas) Managed Code Analysis naming/design rules to fire on internals

A while ago I mentioned that FxCop (and hence Managed Code Analysis) naming and design rules only fire

Wednesday, August 08, 2007 11:12 AM by Noticias externas

# $(CodeAnalysisTreatWarningAsErrors) MSBuild property

For Visual Studio 2008, we have added a new MSBuild property that allows you to easily treat all Code

Wednesday, August 22, 2007 1:52 PM by Luis Fraile

# Agregar "palabros" al diccionario del Code Analysis en Orcas

Al fin!!!!!!!!, algo que ya había comentado como parte de mi participación en el TAP de Orcas, es la

Wednesday, August 22, 2007 1:58 PM by The Visual Studio Code Analysis Team Blog

# New for Visual Studio 2008 - Custom Dictionaries

Once you turn on the new spelling rules that we've added to Visual Studio 2008, you will want to start

Thursday, August 23, 2007 2:49 AM by Luis Fraile

# Agregar "palabros" al diccionario del Code Analysis en Orcas

Al fin!!!!!!!!, algo que ya había comentado como parte de mi participación en el TAP de Orcas, es la

Friday, August 31, 2007 8:13 AM by Gump's blog

# Disable specific Code Analysis rules for a Team Build

After searching a bit, I found a way to disable specific Code Analysis rules for a team build. Or at

New Comments to this post are disabled
 
Page view tracker