问题
doers anyone know of a good utility or program to interrogate a solution or a directory for all projects and tell you where circular references are and possible compile in order..
I remember see one a while ago but i can't find it anywhere..
回答1:
NDepend is an excellent tool that will do this and a lot more. Maybe it's overkill for what you want, but there's a trial version so have a look...
回答2:
I know this is a late answer, but I found using GraemeF and tsilb's answers both showed no dependency between the two assemblies. It looks like if you reverse the order of dependencies (Assembly A references B, but you switch it to B referencing A), it leaves the dependency in the build order. To solve this, open the Properties dialog for your solution, go to Common Properties, and then Project Dependencies. Find the Assembly A and remove the dependency on Assembly B. This will allow you to add the reference normally.
回答3:
You could chase down the dependency tree via System.Reflection. As you build the tree, when adding a node, you would check to see if any parents of the node are the same project or assembly as the one you're adding. If true, throw an exception out to the user.
Throwing technical exceptions like this one are ok if your users will be people who know how assembly references and exceptions work - people like Developers :)
回答4:
If you use project references between the projects in your solution the correct build order will be determined automatically by Visual Studio (or MSBuild). This breaks of course if you use assembly references.. Also Visual Studio will stop you from adding circular project references.
回答5:
I inherited a gigantic visual studio solution with a few circular reference paths. I wrote a linqpad script to help find the circular reference chain:
https://github.com/ronnieoverby/linqpad-utils/blob/master/Find%20circular%20references.linq
My implementation is probably naive, but it worked reasonably fast for me.
来源:https://stackoverflow.com/questions/1669696/c-sharp-utility-to-find-circular-references-compile-in-correct-order