Partager via


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 on publicly visible types and members.

As you may recall, there were a couple of reason for this:

  • The .NET Framework Design Guidelines, which FxCop/Managed Code Analysis enforces, only contains guidelines for publicly visible API. What internal Microsoft teams (and you) do with their internal types and members is completely up to them.
  • Noise. If you tend to wrap a lot of native types and members, then this internal API could be potentially fire numerous violations.

In that same post, I also showed how to override this behavior in in FxCop. Now, since then, I've been asked by a few readers on whether it was possible to do this within Visual Studio 2005, unfortunately, the answer up until now was no.

However, the good news is that in the newly released Visual Studio 'Orcas' Beta 1, we sneaked in a small feature in that allows you to override this on a per-project basis.

To turn it on, simply do the following:

  1. Using Visual Studio, open your project

  2. In Solution Explorer, right-click the project and choose Unload Project, answering Yes to any prompt to save changes

  3. In Solution Explorer, right-click the project and choose Edit

  4. Under the first <PropertyGroup> element, add a new <CodeAnalysisOverrideRuleVisibilities> element with its value set to true:

     <Project DefaultTargets="Build" xmlns="https://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <CodeAnalysisOverrideRuleVisibilities>true < /CodeAnalysisOverrideRuleVisibilities> [..] </PropertyGroup> </Project>

  5. In Solution Explorer, right-click the project and choose Reload Project, answering Yes to both prompts

The naming and design rules (such as IdentifiersShouldBeCasedCorrectly and IdentifiersShouldBeSpelledCorrectly) will now run against all types and members, not just those visible outside of the assembly.

If you want to enable this for all your projects, see the following: FAQ: How do I share Managed Code Analysis rule settings over multiple projects?.

Comments

  • Anonymous
    May 10, 2007
    Srikanth R on Difference between MSBuild and devenv. Paul Hacker on Add the TFS LinksControl to your...