VSCode .editorconfig 无法将设置应用于 C# 代码

Posted

技术标签:

【中文标题】VSCode .editorconfig 无法将设置应用于 C# 代码【英文标题】:VSCode .editorconfig cannot apply settings to C# code 【发布时间】:2021-06-15 06:50:13 【问题描述】:

我正在尝试应用一些设置,例如trim_trailing_whitespace 用于 C# 代码以及 js 部分在 VSCode 中使用以下设置:

# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
trim_trailing_whitespace = true; // it is working for TypeScript and javascript, not C#

[*.md]
max_line_length = off
trim_trailing_whitespace = true

[*.cs]
trim_trailing_whitespace = true; // I add this to make it work for C#

但它不适用于 C# 代码。不能让它在 C# 中工作吗?我只是尝试为trim_trailing_whitespace 测试它,但在使用 TypeScript 和 JavaScript 时不适用于 C#。以下是与此相关的一些信息:

https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019

【问题讨论】:

【参考方案1】:

改变 用于 C# 的 trim_trailing_whitespace 这个“files.trimTrailingWhitespace”

并确保您正在执行以下步骤:

打开 Visual Studio Code 用户设置(菜单 文件首选项设置用户设置选项卡)。 单击窗口右上角的图标。这将打开一个文档。 如果尚未在“用户设置”文档中添加新的"files.trimTrailingWhitespace": true 设置。这样您就不会直接编辑默认设置,而是添加它。 保存用户设置文件。 参考: https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.editor.trimtrailingwhitespace?view=visualstudiosdk-2019

【讨论】:

Perfecto!.. 但在这种情况下,我认为 .editorconfig 设置不能应用于 C# 代码?真的吗?我希望我在 .editorconfig 上进行与 Javascript、Typescript 等文件相同的设置。有什么想法吗? 另一方面,我不能投票给你,你能不能给我的问题投票,这样我才能得到足够的回购来投票?

以上是关于VSCode .editorconfig 无法将设置应用于 C# 代码的主要内容,如果未能解决你的问题,请参考以下文章

EditorConfig for VS Code简述

vscode的格式化问题

vscode的格式化问题

vscode的格式化问题

vscode的格式化问题

vscode 换行符 变成