Thursday, June 19, 2014

Some settings that may be useful if you let StyleCop dictate where to put your using directives.

If you run the default StyleCop rules against your C# code you'll know that it wants you do different things with the order and location of your using directives than Visual Studio does by default.

Having recently discovered that some of the people I've been working with were manually making these changes every time, I highlighted the settings that will do this for you.

Hopefully documenting this here will help other too.


To have Visual Studio put “System” using directives first:

Tools > Options > Text Editor > C# > Advanced > “Organize Usings” > “Place ‘System’ directives first when sorting usings”



To have ReSharper (if you’re using it) put new using directives inside the namespace:

ReSharper > Options > Code Editing > C# > Namespace Imports > “Insert using directives when necessary” > “Add using directive to the deepest scope”

1 comment:

  1. Thanks. This article is very useful with me. It's good for my work.

    ReplyDelete

I get a lot of comment spam :( - moderation may take a while.