"Reorder using statements" moves all usings inside namespace even with "Add 'using' directive to deepest scope" unticked
I prefer my usings outside of the namepsace, so I have the setting "Add 'using' directive to deepest scope" set to false.
This is working fine if I reference a new type and have resharper add the required using directive via Alt-Enter - it gets added outside the namespace.
This also works if I have unused usings and I use Alt-Enter and choose "Remove Unnecessary Usings", the usings stay put.
BUT if I have unordered usings and I use Alt-Enter and choose "Reorder using statements", R# reorders them AND moves them inside the namespace. Having read the numerous topics on these settings I can't find the reason for this behaviour.
I would also add that if I use the built-in Visual Studio function (Ctrl-R, Gtrl-G), that does behave correctly and doesn't move my usings.
Please sign in to leave a comment.
Hello!
Thank you for contacting us.
Could you please provide screenshot illustrating code sample and the correspondent Alt+Enter menu item.
Thanks in advance.
Your request prompted me to create a new empty solution to reproduce the problem in a simple form. I was surprised to find in this example that I get a different popup menu option for reordering the usings which behaves correctly for me:
In my real-life solution, I'm not getting this menu option (which I assume is Resharper), but I get what I now realise is a "Rosalyn Code Fix" - this is the one that moves usings inside the namespace:
It seems this one only shows up when I have the nuget package "Stylecop Analyzers" installed. However, my new question is, why don't the Resharper ones show up in this case?
Back in my clean solution, if I add the Stylecop Analyzers pacakge, I now get both options:
Thank you for the reply and provided screenshots.
Could you please try the following suggestion for the solution you're experiencing problem with - https://resharper-support.jetbrains.com/hc/en-us/articles/206546989-ReSharper-stopped-working-for-a-single-specific-solution
Thank you.
Unfortunately that did not make any difference to this behavior.
Hello!
Thank you for the reply.
Could you please try applying some changes to namespaces list, e.g. reorder them manually and check if ReSharper quick fix appears?
If nothing changes please try the following steps:
- create a new empty solution and check that ReSharper reorder quick fix appears there;
- copy code from new solution to your real-life solution;
- check if ReSharper reorder quick fix appears there.
Thank you.
Manually re-ordering the using list does not cause Resharper to show the quick fix.
In an empty solution, the functionality works. If I copy the code to my real-life solution, the quick fix doesn't appear.
The important point - if I add Stylecop.Analyzers package to my empty solution, the Resharper fixes no longer appear - they are somehow overridden by the presence of Stylecop.Analyzers roslyn code fixes (there was one case where I saw both fixes offered - in the screenshot above, but I can't reproduce that currently).
It so happens that the bug in the Stylecop.Analyzers "Reorder using statements" where the usings also move to the wrong place has been fixed in a beta version of that package, but it would still be good to understand why Resharper is not offering its own quick fix.
Sorry very old post that I am opening up again, I am also seeing this issue today. Any pointers of how you resolved the issue?
Hello @...
Could you please provide the following info:
1. some sample solution in which the problem is reproduced.
2. all dotSettings files by exporting them via ``ReSharper | Manage Options | right-click on each layer | Export to file``.
3. settings.stylecop/.editorconfig if there's any used in the solution.
Thank you.