This project is read-only.

CodeProject.Settings not being merged

Mar 22, 2013 at 11:20 PM
I'm trying to get the SVNStyleCop project using the latest version of StyleCop and I've overcome some issues but I'm hung up on this one.

Below is some simple code to reproduce the issue. I'm using StyleCop V4.7.1000.0
var sourceFile = @"C:\temp\Project\Class1.cs";
var projectSettingsFile = @"C:\temp\Project\project.StyleCop";
var globalSettingsFile = @"C:\temp\global.StyleCop";
var violations = new List<Violation>();
var console = new StyleCopConsole(globalSettingsFile, false, null, null, true, null);
var projects = new List<CodeProject>();
var configuration = new Configuration(new string[0]);
var project = new CodeProject(string.Empty.GetHashCode(), Path.GetDirectoryName(sourceFile), configuration);
project.Settings = console.Core.Environment.GetSettings(projectSettingsFile, true);
console.Core.Environment.AddSourceCode(project, sourceFile, null);
console.ViolationEncountered += (sender, e) => violations.Add(e.Violation);
console.Start(projects, true);
When the file "global.StyleCop" has all rules disabled and the file "project.StyleCop" has rules enabled, there are no violations found. In fact there are violations in the source file being analyzed.

If rules are enabled in the file "global.StyleCop", violations are properly reported.

Both settings files have merge enabled turned on.

Appreciate any advice, Thanks!
Mar 27, 2013 at 11:10 PM
For anyone that has a similar problem, I found that when supplying a path to a settings file in StyleCopConsole ctor, that file of "settings" will override all project "settings". I don't know if this is the intended way for it to work, but you must supply null for the settings path if you want project settings to be used.