Arrange usings inside namespace
Followed by 6 people
Answered
Is there an option to configure Redharper to enforce specifying using statements inside the namespace?
Please sign in to leave a comment.
Hello Boris
ReSharper | Options | Code Editing | C# | Code Style | Reference qualification | Add 'using' directives to deepest scope.
Thanks!
Is there a way to arrange them to be outside the namespace? ReSharper Ultimate 2017.1.2 puts them inside and I can't get them out. Getting this feature working annoys me every time I install ReSharper.
Add 'using' directive to deepest scope is unticked.
Cheers
Craig
@Craig, do you have any plugins installed in ReSharper | Extension Manager? Does it happen during running ReSharper | Edit | Cleanup Code?
Thanks!
Hi Alexander.
Sorry. I just found I had missed your post. The only extension I have is StyleCop by JetBrains (2017.1.1).
Yes. All the using statements end up inside the namespace if I run Cleanup Code.
Cheers
Craig
Alexander, I'm having the opposite problem (the same? I don't really know). I have the "Add 'using' directive to deepest scope" option checked, but when I run "Cleanup Code" it ignores this setting and puts the using statements outside of the namespace. Is there a way to get these two things to work together?
Any further thoughts on this matter? I'm still forced to correct this problem manually.
Cheers
I've been using ReSharper happily since my latest update (2017.2.2). I was ecstatic to find this bug had finally gone away, but I didn't realise StyleCop was no longer active, but now I've had to put StyleCop back in, the ruddy using statements are appearing back inside the namespace again. Ahhh.... So frustrating.
StyleCop should just be complaining about stuff, not doing anything about it.
Cheers
Craig
Hello Craig!
Thank you for the feedback.
Please check if there's option "Fix StyleCop violations" in ReSharper | Options | Code Editing | Code Cleanup | default cleanup profile. If it's there and is ticked please untick it and check if it helps.
Thank you.
Thanks for the suggestion Angelina, but it didn't work. I'm not sure it's related to Code Cleanup. Primarily, it happens when I click the Import 'Namespace' and other missing references? link or I type the name of a class that belongs to an unused namespace. So if I type "Debugger.", as soon as I type ".", I end up with the following.
using System;
using System.Collections.Generic;
using System.Configuration;
namespace MyNamespace
{
using System.Diagnostics;
Hello Craig!
Thank you for the reply.
Unfortunately I cannot reproduce the problem. Do I understand correctly that the problem appears only with StyleCop by Jetbrains extension installed?
Could you please export all your settings layers and provide them to us *(you can do it via 'Submit a request' form).
Thanks in advance.
Yes. Only when StyleCop by JetBrains (2017.2.0) is installed.
Please find exported settings in the following request: https://resharper-support.jetbrains.com/hc/en-us/requests/1138261?page=1
Hello Craig!
Thank you for the provided info.
Could you please check if ReSharper | Options | StyleCop | "Reset StyleCop options" button is greyed out and if it's not please click it.
Then try to reproduce the problem. Let me know about the results.
Thank you.
Hi Angelina. Unfortunately, I still see the same behaviour.
Wait a minute... Where are these Options coming from? I never use this menu option because I want all settings to be team-shared. I was of the understanding that the Options menu rolled all three R# layers up together in order to display the list of "effective" settings and any changes end up applied to the This Computer layer. I can see that Add 'using' directive to the deepest scope is unticked in all three of my layers, yet Options shows it as ticked. If I untick it here, things now work as expected, but the setting is now global on my machine and not available to the team... Nor does it appear as ticked in the This computer layer... I'm confused.
Regards
Craig
Hello Craig!
It's actually StyleCop layer that sets the specified option to True. But it can be easily overridden, just by setting the value in options. The StyleCop settings file is installed to override defaults, but be overridden by just about everything. So you can save to “This Computer” and it will override for all projects, or save to “Team Shared” and have it override just for a single solution.
So open ReSharper | Options | Code Editing | C# | Code Style and untick Add 'using' directive to deepest scope, then click 'Save To' and select any layer.
Here's some more detailed information on how it works - https://github.com/StyleCop/StyleCop/issues/74
Thank you.
I think I found the answer to Craig's problem.
Resharper options > Code Editing > C# > Syntax style
there uncheck "Add 'using' directive to deepest scope"