I wonder if there is a way to strictly control in .Net Core (C#) which namespaces are allowed to be referenced by a certain namespace.
Example
Assume my solution has three namespaces A, B and C.
In namespace C it should be allowed to use classes only from C.
In namespace B it should be allowed to use classes from B and C but not A.
In namespace A it should be allowed to use classes from A and B but not C.
Purpose
You're asking why I want to do that? I want to ensure that developers respect the layer separation (namespaces A, B, C).
What did I try?
- In .Net Framework it was possible to put these three namespaces in three different projects, project A referencing project B and B referencing project C. In .Net Core this doesn't do the job, because in project A it's possible to reference classes from project C!
- Lint for C# doesn't seem to be an alternative.
- I tried to use StyleCop, but I didn't find a rule which is concerning my namespace referencing problem.
Is there any possibility to specify some configuration for allowed and disallowed namespaces and use some sort of automated code analysis which uses that configuration in my build pipeline? Any hint would be highly appreciated!