Code Cleanup - tool to move all using statements inside namespace in all cs files in my solution?
Solution 1
With Resharper it can be done in two steps.
Set the checkbox "Add 'using' directive to the deepest scope" in
Code Editing
→C#
→Code Style
→Reference qualification
.In the context menu of the solution choose "Cleanup Code...".
You might want to create a custom cleanup pofile that suits your needs before performing the cleanup.
In ReSharper before v9 the setting is located somewhere else:
Solution 2
In ReSharper 10 you can find it in:
MoXplod
Updated on June 03, 2022Comments
-
MoXplod almost 2 years
After writing a whole bunch of code - i am finally waking up to adding CA and StyleCop to my solution.
By default all files (a lot of them) in my solution have using statements at the top of the file before the namespace.
I have resharper 6.0 and powertools in visual studio. Is there a way using these or any other tool that will go through all my CS file in the solution and put the using statements inside the namespace for each file.
-
MoXplod over 12 yearsWhat is a custom cleanup profile? Is it easy to setup? So that i can just perform this and it doesnt do other things along with it?
-
Gebb over 12 years@MoXplod A custom profile is a set of your preferences of what ReSharper should do when cleaning up your code. Though the level of customization is not really high, so I'm not sure if it's possible to configure it to only move usings and not do anything else. A profile can be created in Resharper - Options - Code Cleanup.
-
remio over 12 yearsThis cleanup profile management is not the best thing in ReSharper, but it worked nice for me!
-
Liazy almost 8 yearsI found that un-checking the box didn't work as it just removed the entry from the DotSettings file. I checked the box and then manually edited the DotSettings file changing the value for AddImportsToDeepestScope from True to False.
-
Dan Bailiff over 3 yearsIn Resharper 2020.2: Code Editing -> C# -> Syntax Style -> Reference Qualification and 'using' Directives -> Add 'using directive to deepest scope. Not sure why they have to move all the settings with every new version!