.editorconfig
is a standard file that contains lots of different things related to a solution/project. For example almost all the styling rules and analyzer settings can be stored here. The purpose of this file, as discussed here, is to allow you to standardize your editor configuration (related to styles, naming, formatting, etc) and share it with a team. By putting the configuration into a file, the file can be placed into your source control repository and anyone who pulls down the code will automatically use the configured settings instead of whatever defaults they have set up or VS is using. Basically it forces compliance with company-defined rules.
The file itself can be anywhere in the directory structure up to your project file. For example if your code is at c:\projects\company\myproduct
then the file can reside in any directory up to myproduct
. If you have different settings for different projects then it makes sense to put it at the project(solution) level. However many companies have standard settings so it is often put into the higher level company
directory and all solutions/projects created under that will follow the guidance. So in your specific case put the file anywhere in the directory structure but no deeper than where your project file is. I would recommend with the solution file myself. Restart VS and it'll find it.
Alternatively you can go into the VS options where you configure the formatting rules. It has a button to auto-generate a file based upon your current VS settings. This is generally a faster way of generating the file if you're not comfortable with the format.
The file is hierarchical. By default the IDE will load up every .editorconfig
file from the project directory back to the root. This allows you to override settings on a per-project/solution basis. But this can be time consuming so you can optionally add the attribute that marks the config file as root. When the IDE finds a config marked as root it stops walking the directories backwards. If you're using Github repos and plan to share your code then I would recommend you put your config file in the root of your repo and mark it as root so it takes precedence over any other config files.
Note you should not add this file to your project. It is just an extra file (like .gitignore) and doesn't need to be added. It doesn't hurt if you do but it doesn't change anything.
Now, why isn't it working for you. Firstly you should confirm that you're running VS 2022 17.5 Preview 3. This is the first version that supports this feature for C++. If you have a version of VS earlier than that then it won't work for C++ yet. If you are running at least that version then the problem lies elsewhere.