C # + StyleCop + MSBuild + Global culture settings cannot be raised

I have a C # project file configured to import a StyleCop.Targets project that runs all the StyleCop rules on assembly. This is great, and when compiling through Visual Studio, I have a project with zero errors.

However, when I compile through MSBuild (on the same computer), I get errors on a line:

The documentation text within the constructor summary tag must begin with the text: Initializes a new instance of the <see cref="MyClass" /> class.

Focus on the ā€œZā€ in the initializations ... I configured Settings.StyleCop with the en-GB global parameter so that I don't get errors regarding Americanisms in the code. However, I cannot understand why this is causing errors in MSBuild.

I know that MSBuild uses the same Settings.StyleCop file as if I changed the rule (say TabsMustNotBeUsed). MSBuild (and Visual Studio) selects this change and throws errors everywhere.

I am using StyleCop 4.7, Visual Studio 2012 and MSBuild 4.

Here is a snippet of my Settings.StyleCop file:

 <StyleCopSettings Version="105"> <GlobalSettings> <StringProperty Name="Culture">en-GB</StringProperty> </GlobalSettings> <Parsers> <Parser ParserId="StyleCop.CSharp.CsParser"> <ParserSettings> <BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty> </ParserSettings> </Parser> </Parsers> <Analyzers> <Analyzer AnalyzerId="StyleCop.CSharp.SpacingRules"> <Rules> <Rule Name="TabsMustNotBeUsed"> <RuleSettings> <BooleanProperty Name="Enabled">False</BooleanProperty> </RuleSettings> </Rule> </Rules> <AnalyzerSettings /> </Analyzer> </Analyzers> </StyleCopSettings> 

Any clues?

Hooray!

+4
source share
1 answer

I assume that you are using the latest version of StyleCop (4.7.41.0) or a version close to this one. In version 4.7, many changes and fixes were made, and fairly regular updates were released.

I assume there should be another Settings.StyleCop file in the folder hierarchy below (in the subfolder) that sets the culture to ru-US . Changing other rules in this settings file (e.g. TabsMustNotBeUsed) will still behave as expected if you do not set it again in another settings file. A potential reason could be the working folder from which the StyleCop runs.

I suggest performing a quick scan on your file system to see if you can find any other settings files, and if they are found, check their culture settings.

Another trick I did was stop merging in the settings files at the root of the solution. This can be done by adding the following setting:

 <GlobalSettings> <StringProperty Name="MergeSettingsFiles">NoMerge</StringProperty> </GlobalSettings> 

This ensures that StyleCop will act the same on all development and assembly machines, regardless of the settings configured above the hierarchy (for example, the one located in the StyleCop application folder). However, if you do this, be sure to copy all the necessary settings from files that are no longer combined. From your description, I doubt that this will solve this particular problem, but I found it useful to help maintain consistency of rules.

+2
source

Source: https://habr.com/ru/post/1435295/


All Articles