13

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.

Reece
  • 549
  • 9
  • 23
  • 4
    I would report this through VS Feedback, it's likely that the item template is throwing an exception that isn't visible to you. – Jimmy Jan 24 '23 at 18:14

5 Answers5

4

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.

Kevin Scharnhorst
  • 721
  • 1
  • 7
  • 14
1

To elaborate on Shaun Brown's answer:

1st. generate .editorconfig so all the default field are populated.

creating it from VS settings: Tools -> Options -> Text Editor -> C# -> Code Style and selecting the Generate .editorconfig file from settings option.

2nd. go to the solution folder in file explorer. Drag newly generated .editorconfig file into the Visual Studio and the editorconfig UI will be shown.

Video https://www.youtube.com/watch?v=5f1rbw5lOsg

starball
  • 20,030
  • 7
  • 43
  • 238
Mantas
  • 21
  • 2
0

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.

kmaki565
  • 66
  • 4
0

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!!!

John Holliday
  • 1,268
  • 1
  • 11
  • 19
0

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.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • This is actually a good hint! Even if you create the file via Tools >> Options, it will not be visible in the solution items but it does exist. Drag & drop from file explorer to Visual Studio opens it in the expected way. – IngoB Aug 03 '23 at 17:01