Referencing shared project in several projects of solution

前端 未结 3 1611
有刺的猬
有刺的猬 2021-01-18 20:13

I am trying to fix warning

Warning CS0436: The type \'Class1\' in \'...\\SharedProject1\\SharedProject1\\Class1.cs\' conflicts with the imported type

3条回答
  •  星月不相逢
    2021-01-18 20:49

    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.

提交回复
热议问题