You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过ReSharper CLI仅应用.DotSettings文件指定的规则?

如何通过ReSharper CLI仅应用自定义.DotSettings中的规则?

问题背景

我有一个仅包含C#参数位置设置的极简.DotSettings文件,希望通过ReSharper CLI的cleanupcode命令只应用这些规则,不触发任何ReSharper默认的格式化或代码样式规则。

我使用的自定义.DotSettings文件内容如下:

<wpf:ResourceDictionary 
  xml:space="preserve" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:s="clr-namespace:System;assembly=mscorlib" 
  xmlns:ss="urn:schemas-jetbrains-com:settings-storage-xaml" 
  xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_ANONYMOUS_FUNCTION/@EntryValue">Positional</s:String>
    <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_LITERAL/@EntryValue">Positional</s:String>
    <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_NAMED/@EntryValue">Positional</s:String>
    <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_OTHER/@EntryValue">Positional</s:String>
    <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_STRING_LITERAL/@EntryValue">Positional</s:String>
</wpf:ResourceDictionary>

我尝试过以下命令,但仍会应用大量不需要的ReSharper默认规则:

dotnet tool install -g JetBrains.ReSharper.GlobalTools
jb cleanupcode --no-buildin-settings --settings="./../MyCustom.DotSettings" .\MySolution.sln

原本以为--no-buildin-settings会禁用默认规则,但实际并未达到预期效果,请问如何实现仅运行指定的有限规则集?


解决方案

--no-buildin-settings参数确实会禁用ReSharper的内置设置,但ReSharper仍会启用部分隐含的基础格式化规则。要实现仅应用自定义规则,需要通过空白基础设置文件+自定义设置文件的组合来实现:

1. 创建空白基础设置文件(命名为Blank.DotSettings)

这个文件的作用是"清零"所有默认规则,仅启用你需要的参数位置相关规则:

<wpf:ResourceDictionary 
  xml:space="preserve" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:s="clr-namespace:System;assembly=mscorlib" 
  xmlns:ss="urn:schemas-jetbrains-com:settings-storage-xaml" 
  xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <!-- 禁用所有代码检查规则 -->
    <s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/ALL_ERRORS@EntryValue">False</s:Boolean>
    <s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/ALL_WARNINGS@EntryValue">False</s:Boolean>
    <s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/ALL_SUGGESTIONS@EntryValue">False</s:Boolean>
    <s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/ALL_HINTS@EntryValue">False</s:Boolean>

    <!-- 禁用全局格式化开关,仅启用指定的参数位置规则 -->
    <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ENABLED@EntryValue">False</s:Boolean>
    <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_ANONYMOUS_FUNCTION@Enabled">True</s:Boolean>
    <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_LITERAL@Enabled">True</s:Boolean>
    <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_NAMED@Enabled">True</s:Boolean>
    <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_OTHER@Enabled">True</s:Boolean>
    <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ARGUMENTS_STRING_LITERAL@Enabled">True</s:Boolean>
</wpf:ResourceDictionary>

2. 使用CLI命令合并设置

通过分号分隔多个设置文件,先加载空白基础设置,再加载自定义设置(自定义设置会覆盖空白文件中的对应配置):

jb cleanupcode --no-buildin-settings --settings="Blank.DotSettings;./../MyCustom.DotSettings" .\MySolution.sln

关键说明

  • --no-buildin-settings确保ReSharper仅使用你指定的设置文件,不加载内置默认规则
  • 空白设置文件负责禁用所有不需要的规则,只保留需要的规则开关
  • 多个设置文件的加载顺序为从左到右,后面的文件会覆盖前面文件中的相同配置项

内容的提问来源于stack exchange,提问作者Svish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 04:21:02