使用 Resharper 进行 .editorconfig dotnet 命名设置

发布于 2025-01-13 04:23:03 字数 1684 浏览 5 评论 0原文

我需要一些帮助来理解与 .editorconfig 文件相关的一些行为以及它与命名约定和继承相关的行为。 因此,我想为某个项目引入类似于 SomeType_RestOfTheName 的命名样式。但是,我只想将此名称更改应用于某个项目,而不是全局应用于解决方案。这意味着我最终得到的结构类似于:

+ <root>
    - Root.sln
    - .editorconfig // has the root = true flag
    + test
        + project
            - project.csproj    
            - .editorconfig

名称是任意的。
现在项目文件夹下的 .editorconfig 是我添加的,它具有以下内容:

[*]
# Microsoft .NET properties
dotnet_naming_rule.types_and_namespaces_rule.import_to_resharper = as_predefined
dotnet_naming_rule.types_and_namespaces_rule.resharper_style = AaBb, SomeType_ + AaBb
dotnet_naming_rule.types_and_namespaces_rule.severity = warning
dotnet_naming_rule.types_and_namespaces_rule.style = upper_camel_case_style
dotnet_naming_rule.types_and_namespaces_rule.symbols = types_and_namespaces_symbols
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
dotnet_naming_symbols.types_and_namespaces_symbols.applicable_accessibilities = *
dotnet_naming_symbols.types_and_namespaces_symbols.applicable_kinds = namespace,class,struct,enum,delegate

如您所知,其他设置将从根目录中的 .editorconfig 继承,并且只有目标项目才会具有特定的命名约定。
注意:这确实适用于适当的命名风格。
现在我的问题。
如果我移动或注释掉上面的任何设置,整个命名约定就会失败并出现警告。这是为什么?所有这些设置是否需要一起配置才能正常工作?关于 .editorconfig 文件的继承;如果我要将所有这些设置(期望 dotnet_naming_rule.types_and_namespaces_rule.resharper_style = AaBb, SomeType_ + AaBb 设置)移动到根 .editorconfig 文件,命名约定也会失败吗?这是为什么?我认为它要么使用默认值,要么在根目录中查找根 .editorconfig 中的值?
在 Rider 和 VS + Resharper 中都没有发生这种情况,所以不确定它是 Resharper 或 Rider 相关的事情,或者是否与需要定义某些设置(即需要全部设置在一起)有关?

I am needing some help in understanding some of the behaviour related to .editorconfig file and how it behaves in relation to naming convention and inheritance.
So I would like to introduce a naming styling for a certain project something akin to SomeType_RestOfTheName. However, I only want this name change to apply to a certain project not globally to the solution. This means I have end up with a structure similar to:

+ <root>
    - Root.sln
    - .editorconfig // has the root = true flag
    + test
        + project
            - project.csproj    
            - .editorconfig

The names are arbitrary.
Now the .editorconfig under the project folder is the one I have added and it has the following contents:

[*]
# Microsoft .NET properties
dotnet_naming_rule.types_and_namespaces_rule.import_to_resharper = as_predefined
dotnet_naming_rule.types_and_namespaces_rule.resharper_style = AaBb, SomeType_ + AaBb
dotnet_naming_rule.types_and_namespaces_rule.severity = warning
dotnet_naming_rule.types_and_namespaces_rule.style = upper_camel_case_style
dotnet_naming_rule.types_and_namespaces_rule.symbols = types_and_namespaces_symbols
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
dotnet_naming_symbols.types_and_namespaces_symbols.applicable_accessibilities = *
dotnet_naming_symbols.types_and_namespaces_symbols.applicable_kinds = namespace,class,struct,enum,delegate

As you can tell the other settings will be inherited from the .editorconfig in the root, and only the target project will have the specific naming convention.
NOTE: This works it does apply the appropriate naming style.
Now for my question.
If I move or comment out any of those settings above the whole naming convention fails with warnings. Why is that? Do all of these settings need to be configured together for it to work? And in respect to inheritance of the .editorconfig files; if I were to move all those settings expect the dotnet_naming_rule.types_and_namespaces_rule.resharper_style = AaBb, SomeType_ + AaBb setting to the root .editorconfig file the naming convention fails as well? Why is that? I thought that it would either use default or find the values in the root to the root .editorconfig?
Not this happens in both Rider and VS + Resharper, so not sure it is a Resharper or Rider related thing, or if it has to do with how some settings need to defined (i.e. the need to all be set together)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2025-01-20 04:23:03

对于任何好奇的人来说,这更多的是用户的误解而不是问题。在关于 .editorconfig 文件中命名样式的 MS 文档中,有这样一行:

All naming rule properties are required for a rule to take effect.

在使用 .editorconfig 命名设置后,我意识到我误解了结构一点点。下面我修改了上面的结构,希望对于遇到此问题的任何人来说它都是有意义的:

[*]
# Microsoft .NET properties - SomeType_ naming rule block
dotnet_naming_rule.sometype_prefix_rule.import_to_resharper = as_predefined
dotnet_naming_rule.sometype_prefix_rule.resharper_style = AaBb, SomeType_ + AaBb
dotnet_naming_rule.sometype_prefix_rule.severity = warning
dotnet_naming_rule.sometype_prefix_rule.style = upper_camel_case_style
dotnet_naming_rule.sometype_prefix_rule.symbols = sometype_prefix_symbols
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
dotnet_naming_symbols.sometype_prefix_symbols.applicable_accessibilities = *
dotnet_naming_symbols.sometype_prefix_symbols.applicable_kinds = namespace,class,struct,enum,delegate

但归根结底,您使用自定义名称定义自定义规则,并且必须配置所有相关属性,否则定义格式错误且未应用。

For anyone that is curious, this was more of a user misunderstanding than an issue. On the MS documentation regarding naming styles in the .editorconfig file there is this line:

All naming rule properties are required for a rule to take effect.

Pretty much after playing around with the .editorconfig setting for naming I realized I was misunderstanding the structure a tad. Below I have modified the structure from above, hopefully for anyone that comes across this it makes sense:

[*]
# Microsoft .NET properties - SomeType_ naming rule block
dotnet_naming_rule.sometype_prefix_rule.import_to_resharper = as_predefined
dotnet_naming_rule.sometype_prefix_rule.resharper_style = AaBb, SomeType_ + AaBb
dotnet_naming_rule.sometype_prefix_rule.severity = warning
dotnet_naming_rule.sometype_prefix_rule.style = upper_camel_case_style
dotnet_naming_rule.sometype_prefix_rule.symbols = sometype_prefix_symbols
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
dotnet_naming_symbols.sometype_prefix_symbols.applicable_accessibilities = *
dotnet_naming_symbols.sometype_prefix_symbols.applicable_kinds = namespace,class,struct,enum,delegate

But it boils down to the fact that you define a custom rule with a custom name, and you have to configure all the relavent properties otherwise the definition is malformed and not applied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文