I created a project and added a ruleset file. I then broke the rule on purpose to ensure that it was working, but it wasn’t.
Here is the rule I enabled.
CA2211 – Microsoft.Usage –
“Non-Constant fields should not be
visible.”
Bad Code:
public class Foo
{
public string foobar = "Hello World";
}
It compiles just fine, no warning or error. I think it might have to do with ReSharper overriding it? I’m not sure. Any thoughts as to how to fix this?
According to Compare Visual Studio 2010 Products…
If you are running VS 2010 Premium or Ultimate you should have “Static Code Analysis” available. If you are and that feature is not showing up, you might look at reinstalling Visual Studio. If you aren’t running either of those, you won’t have access to that feature, sorry.
However, you can still use FxCop to validate your code.
NOTE: The link is to FxCop 10.0.