简体   繁体   中英

c# : Utility to find circular references / compile in correct order?

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..

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...

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.

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 :)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM