有没有办法在 Visual Studio 中为整个解决方案或项目将 EOL 设置为 LF?

Is there a way to set EOL to LF in Visual Studio for whole solution or project?

在Visual Studio中,您可以将文件的 EOL 设置为 CRLF、LF 或 CR,但是您只能对单个文件执行此操作。我正在寻找一种方法来确保我的解决方案中创建的每个新文件都将自动使用 LF。有任何想法吗?提前致谢!

因为默认settings.json包含"files.eol": "auto",您可以在VSCodedocumentation. You need set The default end of line character to appropriate value, e.g.:

下浏览

如果您正在寻找一种方法来控制在 Windows 中打开文件的默认翻译模式,您可以使用 _set_mode() 或设置 _fmode 记录的全局变量 here:

    int _fmode = _O_BINARY;

或在运行时间:

    _set_mode(_O_BINARY);  // defined in `<stdlib.h>`

似乎有一种方法可以通过修改 Global state in the CRT 来更全局地设置它,但细节超出了我在这个环境中的技能水平。

在项目(或解决方案)的根目录中添加具有以下条目的 .editorconfig 文件应默认将行结尾设置为 LF(对于新添加的行,请参阅下面的注释).

    [*]
    end_of_line = lf

引自 Create portable, custom editor settings with EditorConfig 页面。

You can add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase.

The editor in Visual Studio supports the core set of EditorConfig properties:
[...]   end_of_line

When you add an .editorconfig file to a folder in your file hierarchy, its settings apply to all applicable files at that level and below.

When you add an EditorConfig file to your project in Visual Studio, new lines of code are formatted according to the EditorConfig settings. The formatting of existing code is not changed unless you run one of the following commands:

  • Code Cleanup (Ctrl+K, Ctrl+E), which applies any white space settings, such as indent style, and selected code style settings, such as how to sort using directives.

  • Edit > Advanced > Format Document (or Ctrl+K, Ctrl+D in the default profile), which only applies white space settings, such as indent style. Note