Referencing shared project in several projects of solution

六月ゝ 毕业季﹏ 提交于 2019-12-01 17:52:41

Change the dependency schema from:

Shared -> Class
Shared -> Application

to:

Shared -> Class -> Application

That is: remove from Application a direct reference to Shared.

The first schema results in same class built into 2 dlls. That's what causes the conflict. In the second schema the shared library is built into Class dll and thus is also accesible to Application.

The first schema would be ok, if Class and Application were independent of each other.

All of this is because a shared project does not generate a library. So one must think about making it appear somewhere in a library. Usually only in one place. That usually means, that each shared library should be referenced only once.

Jarekczek's solution works fine when you have only one class library, but as soon as you add another class library which also references the shared project, you get the same warning again.

The solution might be obvious, but if it's not here it is...

You could create one more ordinary class library project named 'Common' which doesn't contain any classes on it's own, but only references shared project. It serves as a 'container' for shared code.

So reference tree could look like this:

SharedProject -> Common
Common -> ClassLibrary1
Common -> ClassLibrary2
ClassLibrary1 -> Application
ClassLibrary2 -> Application
Common -> Application

Try to change your code as :

       namespace SharedProject1{public class Class1() { }}

In your project WpfApplication1 you must add references to SharedProject1 and ClassLibrary1 ,it hork after that :

I have create a project for you with your specefication :

Project exemple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!