Search code examples
visual-studiovisual-studio-2017

Visual studio 2017 reorders includes without asking


I was programming c++ in Visual studio 2017 and I suddenly noticed that visual studio had changed my includes to be ordered alphabetically. I'm not sure what triggered this reordering.

I don't mind some of the other formatting that happens but I don't want my include order to be changed.

There is one include in our header files ..._precompiled.h that always needs to be first or compilation can give problems. Is there anyway to disable this?

It might also be visual assist behavior but I don't think so since I didn't have this problem in vs2013.

Update:
My colleague suspects "Options->Text editor->C/C++->Formatting->Enable ClangFormat Support" lies at the root of the problem. Enable ClangFormat support We don't yet knows what triggers the formatting so I'm not sure this is the problem.

Does anyone based on this information have an idea what could trigger the formatting and reorder of the includes?


Solution

    1. Find the trigger of the sorting.Common triggers are save,save all, format document & code clean up.

    2. Disable all plugins and activate the trigger you found. If it triggers it is Visual Studio else a Plugin.

    Visual Studio cause:

    Tools => Options => Text Editor => Your language => Advanced => Using directives
    

    other possible paths for settings that could cause:

    Tools => Options => Text Editor => Your language => Code Style => Formatting => Sort Usings
    

    or

    Tools => Options => Text Editor => Your language => Code Style => Formatting => ClangFormat support (disable it)
    

    Plugin cause:

    • Known plugin with that functionality (Resharper, CodeMaid)
    • Enable plugins one by one to find the specific plugin.
    • Google about it and update that list :)