I want to set up some new dependency rules for a repo which has multiple solutions and assemblies. Rule should be, such as:- in any project, all the assemblies of type .ABC. should not depend upon .XYZ.. Any violation of such rule should be caught either during building an assembly or during CI.
1.I tried NsDepCop. There I created a config.NSDepCop file for rules. But the ‘config.nsdepcop file’s build action is not set as C# analyzer additional file due to which Visual studio is unable to detect config.nsdepcop file as C# analyzer file and on building the solution the dependency rules analyzed.
Another ways are "Custom Roslyn rules", "Resharper", FxCop custom rules and NDepend but I have little to no idea about these.
Could anyone please help me out here?
With NDepend a rule is a C# LINQ query with a special rule header
warnif count > 0
. Thus the rule mentioned in the question can look like:Of course you can refine the
Where(a => ...)
clauses to your exact context.Running the Dependency Rule after Building and in CI
NDepend code rule(s) can be validated:
Using the Dependency Rule result to remove a matched dependency
The rule could be refined to match culprit classes and methods when a dependency is found between an ABC assembly and a XYZ assembly. However it is more practicable to: