Question

I have three projects in my .net solution.
The main project and two class library projects.

I have found out that I need to cross reference the class library projects.
Can I do that? Is it safe or there are some considerations?

Was it helpful?

Solution

The IDE won't let you when the projects are in one solution. There are subtle ways to confuzzle it. But then the solution cannot be built from scratch (i.e. Build + Rebuild) since the assembly reference isn't available yet. Refactor this, you probably want a 3rd assembly that both can reference.

OTHER TIPS

Circular references are possible (via the command-line and some tricks; not via the IDE) but are a major pain; don't do it!

Either add an extra assembly for the common types, or merge the two libraries.

In many ways, fewer is simpler... A myriad of dlls doesn't mean that you have achieved purity - it is just a mess.

When I have run into this problem, I have created classes that only have properties. Could be Employee, Customer, Product, whatever. Those classes don't need to reference any other project, so multiple projects can reference them.

The methods that belong to those objects (Employee, Customer, Product) then go into their own classes in the other projects.

One situation where I have encountered this quite often is in a three-layered application - presentation layer, business layer, and data access layer. I want the DAL to retrieve data and populate an Employee object, which is returned to the BLL. If the Employee class is in the BLL and has both properties and methods, then there is no easy way to populate an Employee object in the DAL and return it to the BLL -- because the BLL must have a reference to the DAL, so the DAL cannot in turn reference the BLL. Creating the separate project with properties-only classes (Employee, Customer, Product) is one way to solve this problem.

If by "cross reference", you mean that you want to do the following:

1) Project MAIN contains references to LIBRARY-ALPHA and LIBRARY-BETA

2) Project LIBRARY-ALPHA contains references to LIBRARY-BETA

3) Project LIBRARY-BETA contains references to LIBRARY-ALPHA

then no. Visual Studio will be unable to build MAIN until it builds ALPHA and BETA. It will be unable to build ALPHA until it builds BETA. And it will be unable to build BETA until it builds ALPHA. Therefore, it will be unable to build anything.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top