0

I would like to have StyleCop rules apply on a specific namespace (all classes from this namespace are in the same folder).

My project structure looks like this:

  • Folder1
    • Class1.cs
    • Class2.cs
    • Settings.StyleCop (namespace settings)
  • Class3.cs
  • Class4.cs
  • Settings.StyleCop (general settings)

The general settings are correctly applied to all files (including the ones in the subfolder), but the namespace settings are completely ignored.

I haven't used StyleCop in a while, but I thought this was possible. Am I doing something wrong?

How can I make this work?

Raya
  • 101
  • 1
  • 7

1 Answers1

1

I don't think it's possible with Stylecop. I made some experiments and the rule file in the subfolder was always ignored.

I think it only works on a project level. I didn't go through the source code but placed a new C# file under the project without adding it to the project and it didn't analyze it which suggests it finds the code files by looking at the project file and ignoring any files just lying in that folder.

Also if you delete the Settings.Stylecop file under the project folder and select Stylecop Settings in Visual Studio it automatically creates a new Settings.Stylecop file even if you don't save the settings which also made me think it's highly coupled to the project file.

I'd suggest to move the contents of the Folder1 to a different class library and apply a different settings file to that project. You can merge settings with the other project and decide which rules apply to which project.

Volkan Paksoy
  • 6,727
  • 5
  • 29
  • 40
  • I found [this answer](http://stackoverflow.com/questions/13843148/how-to-suppress-a-stylecop-warning-of-entire-namespace-files), which seems to suggest that what I'm trying to do is possible... But maybe it's not. – Raya Jul 22 '15 at 15:35
  • Yes looks like it. I wasn't aware of file lists. I think the first sentence confirms by default it works on project basis: "StyleCop makes it easy to configure the rules that should run for a particular project, but until now there hasn’t been a straightforward way to set up alternate rules for specific files within a project." The Limitations it mentions is a bit offputting but it's good to know it's technically possible. – Volkan Paksoy Jul 22 '15 at 15:42