简体   繁体   English

禁用解决方案中特定项目的stylecop分析

[英]Disable stylecop analysis for specific projects within solution

Is there a way to easily stop StyleCop warnings from being displayed within specific projects in a solution. 有没有办法轻松阻止StyleCop警告显示在解决方案中的特定项目中。 Or, more pointedly, a way to select which projects StyleCop analysis should be performed on by Visual Studio? 或者更确切地说,是一种选择Visual Studio应该对哪些项目进行StyleCop分析的方法?

We have a solution with 9 projects in it. 我们有一个包含9个项目的解决方案。 There are only 2 projects that I actually want to see StyleCop warnings for, so I've created StyleCop.Settings files within those project root directories. 我实际上只想看到2个项目的StyleCop警告,所以我在那些项目根目录中创建了StyleCop.Settings文件。 This means that, for the rest of the projects, the default rule set is applied and I get a screen full of warnings every time I open a class. 这意味着,对于其余项目,将应用默认规则集,每次打开课程时,我都会看到一个充满警告的屏幕。

The only way I can think to remove these warnings is to add another StyleCop.Settings file a folder level above with all the rules switched off and set merge options on the specific Settings files I am interested in to not merge with this parent file. 我能想到删除这些警告的唯一方法是在上面的文件夹级别添加另一个StyleCop.Settings文件,关闭所有规则,并在我感兴趣的特定设置文件上设置合并选项,以便不与此父文件合并。 This just feels wrong though. 这只是感觉不对。 Is there a cleaner option or is this my only one? 有更清洁的选择还是我唯一的?

UPDATE: I'm specifically looking for a way to stop the warnings from appearing within Visual Studio. 更新:我正在寻找一种方法来阻止警告出现在Visual Studio中。 I've added a Settings.StyleCop file to the solution folder and disabled all the rules. 我已将Settings.StyleCop文件添加到解决方案文件夹并禁用所有规则。 I run StyleCop analysis across one of my test projects and there are no errors reported. 我在我的一个测试项目中运行StyleCop分析,并且没有报告错误。 However, opening a test class reveals a raft of StyleCop warnings, which I want to suppress. 但是,打开一个测试类会发现一大堆StyleCop警告,我想要压制它。 Could this be the StyleCop for ReSharper plugin? 这可能是ReSharper插件的StyleCop吗? I have a code cleanup profile created and have disabled certain rules within there but that doesn't appear to make any difference within my test classes. 我创建了一个代码清理配置文件,并在那里禁用了某些规则,但这似乎在我的测试类中没有任何区别。

Please have a look at File Lists configuration - they allow to disable rules by default per project: 请查看文件列表配置 - 它们允许每个项目默认禁用规则:

Enabled Or Disabled By Default 默认情况下启用或禁用

In addition, a new setting allows you to determine whether rules should be enabled or disabled by default. 此外,新设置允许您确定默认情况下是应启用还是禁用规则。 This can be set either at the project level or at the SourceFileList level. 这可以在项目级别或SourceFileList级别设置。 For example, here's how you would set up a project with all rules disabled by default, and only two rules explicitly enabled: 例如,以下是默认情况下禁用所有规则设置项目的方法,并且只显式启用了两个规则:

<StyleCopSettings Version="4.3">
    <GlobalSettings>
        <BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
    </GlobalSettings>

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

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