简体   繁体   English

Stylecop忽略子文件夹中的设置文件

[英]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). 我希望将StyleCop规则应用于特定的名称空间(该名称空间中的所有类都在同一文件夹中)。

My project structure looks like this: 我的项目结构如下:

  • Folder1 资料夹1
    • Class1.cs Class1.cs
    • Class2.cs Class2.cs
    • Settings.StyleCop (namespace settings) Settings.StyleCop (命名空间设置)
  • Class3.cs Class3.cs
  • Class4.cs Class4.cs
  • Settings.StyleCop (general settings) Settings.StyleCop (常规设置)

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. 我已经有一段时间没有使用StyleCop了,但是我认为这是可能的。 Am I doing something wrong? 难道我做错了什么?

How can I make this work? 我该如何进行这项工作?

I don't think it's possible with Stylecop. 我认为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. 我没有查看源代码,而是在不将其添加到项目中的情况下在项目下放置了一个新的C#文件,并且它也没有对其进行分析,这表明它通过查看项目文件并忽略了所有文件而找到了代码文件在那个文件夹中。

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. 另外,如果您删除项目文件夹下的Settings.Stylecop文件并在Visual Studio中选择Stylecop Settings,即使您不保存设置,它也会自动创建一个新的Settings.Stylecop文件,这也使我认为它与项目文件高度相关。

I'd suggest to move the contents of the Folder1 to a different class library and apply a different settings file to that project. 我建议将Folder1的内容移动到其他类库,并将不同的设置文件应用于该项目。 You can merge settings with the other project and decide which rules apply to which project. 您可以将设置与其他项目合并,并确定哪些规则适用于哪个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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