Search code examples
c#visual-studiostylecop

Not getting error on changing the coding validation rule in stylecop.json


I made followinh changes to the stylecop.json file

"orderingRules": {"usingDirectivesPlacement": "insideNamespace"}

But i am only getting warning and not error in the cs files.

When i place the using directive outside the namespace i don't get any error.


Solution

  • Please try the following steps:

    1. Create a new editorconfig File in your project

    enter image description here

    enter image description here

    1. Open the editorconfig File, find the perferred 'using' directive placemen in Code Style and adjust it to inside namespace

    enter image description here

    1. Save the editorconfig File, and then you will put the using directive in the namespace when you create the class again.

    enter image description here

    Finally, you also need to refer to Should "using" directives be inside or outside a namespace in C#?. Because usually stylecop will not check the code outside the namespace