Why is StyleCop SA1305 not respecting the allowed prefixes list in VS2010 (or MSBuild)?
-
11-09-2019 - |
Question
I just upgraded a project from 2008 to 2010 Beta 2 and StyleCop is now reporting SA1305 (Hungarian notation) warnings on variable names with the prefix 'is'. 'Is' is definitely in the list of allowed prefixes.
Is this a known issue? Has anyone else run across this problem? The code was definitely compiling without any warnings in 2008.
Update: It turns out that this can work as expected in Visual Studio, but then fail through MSBuild. See the answer below for why.
Solution 2
I ran across a similar issue now when building with msbuild vs on a developer box. It turns out that the default Settings.StyleCop (C:\Program Files (x86)\MSBuild\Microsoft\StyleCop\v4.4
) that is installed actually contains a bunch of values you will need to duplicate in your own file if either:
- you are not installing StyleCop on the "other" (build) machine
or
- you have "do not merge with any other settings files" enabled
Specifically - the StyleCop Settings Editor picks up the Hungarian notation excludes from the other file automatically, regardless of what the "Settings Files" tab says.
OTHER TIPS
You can manually add the "is" exception to Settings.StyleCop:
<Analyzers>
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
<AnalyzerSettings>
<CollectionProperty Name="Hungarian">
<Value>is</Value>
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>
</Analyzers>
just add it like this:
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
<AnalyzerSettings>
<CollectionProperty Name="Hungarian">
<Value>is</Value>
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>