skip to Main Content

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.

4

Answers


  1. 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.

    Login or Signup to reply.
  2. It gets worse:

    1. Tools > Options > Text Editor > C# > Code Style > Generate .editorconfig
    2. Select the solution folder and save the generated file
    3. Right click the solution node and Add Existing Item
    4. Select the .editorconfig file
    5. Right click the file, select "Open With" and then choose "Source Code (Text) Editor"

    Visual Studio hard crash!!!

    Login or Signup to reply.
  3. I also have this issue. I tried to create an issue using the Visual Studio submit Feedback option, but I was unable to get it to submit.

    The best workaround that I have found is opening the solution in VS 2019. Add the .editorconfig item to the solution there. Save and close VS 2019. Open the solution in VS 2022 and viola the .editorconfig file is visible in the Solution Items pseudo folder as it should have appeared with VS 2022.

    You can open the solution file in Notepad++ to see the differences that are being written to the file as you overwrite the 2022 version with 2019, and then again as you re-save the 2019 file in 2022.

    Login or Signup to reply.
  4. Found this video, a Workaround.

    You will not be able to view in solution explorer, but you can drag the created .editorconfig file into editor to change.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search