4

Is there a way to configure ReSharper to add using references to a file within the appropriate namespace?

Currently it adds them to the top of the file, which is fine, until you want multiple namespaces in the same file.

For example, I would like it to be like the following:

namespace A
{
    using System;

    // other classes
}

2 Answers 2

8

Options > Code Editing > C# > Namespace Imports:

Insert using directives when necessary > Add using directive to the deepest scope.

Namespace Imports

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, the screenshot was very helpful too.
On my machine, it wasn't in these options but I searched for "Deepest scope" and found where it got moved . (Personally it was in C# > Syntax Style)
3

Just to bring an up to date answer here as I was wanting to do this but not having R# (ReSharper) installed...

Its now available from Visual Studio 2019 directly since the 16.1 Release.

I found this on developercommunity.visualstudio.com

The code style to include using directives inside or outside a namespace was added in Visual Studio 2019 update 16.1. You can now set your preference in Tools > Options > Text Editor > C# > Code Style or in an EditorConfig file and the IDE can apply it through messages, warnings, or errors depending on the severity you specify in the code style rule

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.