Cross referencing assemblies

2019-02-24 05:37发布

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?

4条回答
来,给爷笑一个
2楼-- · 2019-02-24 06:02

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.

查看更多
男人必须洒脱
3楼-- · 2019-02-24 06:13

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.

查看更多
该账号已被封号
4楼-- · 2019-02-24 06:14

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.

查看更多
smile是对你的礼貌
5楼-- · 2019-02-24 06:18

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.

查看更多
登录 后发表回答