简体   繁体   中英

Stylecop ignores settings file in subfolder

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM