简体   繁体   中英

Visual Studio 2022 unable to create .editorconfig file

Using Visual Studio Community 2022, version 17.4.4.

I just created a WPF (.NET Framework) solution using the built in VS template. To this solution, I wanted to add a .editorconfig file to aid with code formatting. However, when right clicking the solution in Solution Explorer and following Add -> New Item... -> editorconfig File (.NET) and naming it .editorconfig , Visual Studio simply does not create it.

I followed these same steps again, but instead selected to add a plain .txt file and it seemed quite happy creating it.

It's worth noting that I can add a new .editorconfig to projects within the solution, but as I plan to add more projects in the future, I would like the solution itself to contain a top level .editorconfig rather than need to duplicate it per project.

I have tried restarting VS, updating it, repairing it, and creating a completely separate solution. I get the same results. I'm aware .editorconfig files are just plaintext files themselves, and that I can create a blank file and type into it manually, but ideally I want all of the presets to be populated out of the box.

Any help would be appreciated.

EDIT : I managed to temporarily get around it by creating it from VS settings: Tools -> Options -> Text Editor -> C# -> Code Style and selecting the Generate.editorconfig file from settings option. From here I select the solution folder. This doesn't solve the original issue that the add context menu option doesn't create it, however.

I met the same issue with my WPF (.NET 6) project. Having a solution item folder just for.editorconfig looked to me overkill anyway, so what I did was:

  1. Start another VS instance and create a new WPF solution
  2. Add new EditorConfig for the project
  3. Choose settings and save the config
  4. Open Explorer and copy the generated file to the original solution's root folder (you could remove all lines except for those you have modified)

The.editorconfig will be tracked by source control without messing up the VS solution view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM