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

如何让JetBrains CleanupCode格式化csproj、props及targets文件?

让JetBrains CleanupCode格式化csproj/props/targets等XML文件的方法

问题根源

CleanupCode默认未将csproj、props这类XML格式的项目文件纳入自动格式化范围,且原有editorconfig配置的规则写法或指向存在问题。

修正步骤

  1. 调整editorconfig配置
    替换原有配置为更明确的XML格式化规则,确保CleanupCode能识别并应用:

    [*.{csproj,sfproj,dbproj,webproj,deployproj,props,targets}]
    indent_style = tab
    indent_size = 4
    # 启用XML缩进保留与空行控制
    resharper_xml_keep_indents = true
    resharper_xml_keep_blank_lines = 1
    # 指定对这类文件使用内置的"Reformat Code"清理配置
    resharper_cleanup_code_profile = Built-in: Reformat Code
    
  2. 运行CleanupCode时明确指定文件类型
    命令行执行时,需显式包含目标文件类型,避免被默认规则忽略:

    cleanupcode --include="**/*.csproj" --include="**/*.props" --include="**/*.targets" YourSolution.sln
    
  3. 匹配ReSharper IDE中的XML格式化设置
    打开IDE的ReSharper设置(File → Settings → ReSharper → Options),进入Code Editing → XML → Formatting Style,确保缩进、换行等规则与editorconfig完全一致,避免规则冲突。

  4. 清理缓存确保配置生效
    若修改后仍无效果,可清理CleanupCode缓存:

    cleanupcode --cleanup-cache
    

    或在IDE中执行File → Invalidate Caches...,重启后再尝试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 19:02:35