How to tell ReSharper to sort usings with system namespaces NOT at the top?

ResharperVisual Studio-2012

Resharper Problem Overview


Visual Studio has an option to place system directives at the top when sorting them.

enter image description here

When this setting is unchecked, sorting using statements by right-clicking on them and using the Organize Usings feature, places System namespaces alphabetically along all other namespace imports.

However, ReSharper does not seem to honor this setting, nor does it have anything similar on its own Namespace Imports options page. It always behaves as if you want System namespaces at the top. This is especially annoying when you already have some at the bottom and you let ReSharper suggest a namespace to import, then you end up with some at both ends of the list.

Is there some way to fix this? Or is this just a bug/oversight in ReSharper?

Resharper Solutions


Solution 1 - Resharper

I am using ReSharper 7 and at least for me ReSharper takes the "System directive sorting option" from Visual Studio options.

Sometimes when VS and ReSharper settings get messed it helps to reset Visual Studio settings from Tool->Import and Export Settings->Reset all settings.

Solution 2 - Resharper

I was testing this again under ReSharper 8 to see if it's been fixed, and I noticed something interesting:

  • If my existing namespaces already have System items first, then ReSharper will insert new namespaces below them.

  • If my existing namespaces have at least one item before the System items, then ReSharper will insert new namespaces alphabetically.

  • ReSharper's behavior is the same regardless of the setting of Visual Studio. It only takes into consideration the existing namespaces - not the setting of Visual Studio.

So if I have the following:

using A;
using System;
using Z;

Then if I use a class from namespace B and alt-enter to let ReSharper add the namespace, it will end up as:

using A;
using B;
using System;
using Z;

BUT, if I just have this:

using System;
using Z;

And I do the same exact thing, then I'll get:

using System;
using B;
using Z;

And it doesn't matter what VS's setting is.

I assume this is what was happening in ReSharper 7 also and I just didn't notice.

Solution 3 - Resharper

If I cut all the usings, then I paste them where they were, and then do the sorting, it seems to respect the option:

Place 'System' directives first when sorting usings

I'm testing this on Visual Studio Community 2017 and Resharper 2018.3.4.

Solution 4 - Resharper

Screenshot

ReSharper | Options | Code Editing | C# | Syntax Style | Reference Qualification and 'using' Directives | Place 'System.*' and 'Windows.*' namespaces first when sorting 'using' directives

Deselect it.

See also this ReSharper help document: Code Syntax Style: Namespace Imports - Configure namespace imports preferences

Solution 5 - Resharper

Versions: Resharper 2021.2 and VS Studio 2019 Professional

The setting concerned with the issue was checked by default on Resharper: enter image description here

However, this alone did not put 'System' usings first.

But upon checking the VS Studio setting, Ctrl+R,Ctrl+ G works as expected: enter image description here

Solution 6 - Resharper

For ReSharper 2019.2.3

ReSharper -> Options -> Code Editing -> C# -> 
Code Style -> Reference Qualification and 'using' Directives 

and then uncheck the checkbox

🔲 Place 'System.*' and 'Windows.*' namespaces first when sorting 'using' directives 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatt Johnson-PintView Question on Stackoverflow
Solution 1 - ResharperFiilipView Answer on Stackoverflow
Solution 2 - ResharperMatt Johnson-PintView Answer on Stackoverflow
Solution 3 - ResharperPablo Carrasco HernándezView Answer on Stackoverflow
Solution 4 - Resharper黎御衡View Answer on Stackoverflow
Solution 5 - ResharperbasecampView Answer on Stackoverflow
Solution 6 - ResharperBalianytsia ArtemView Answer on Stackoverflow