我有一个“共同”项目。我们称它为:MyProject.Common 该项目有一个命名空间 Serials.Licensing,其中包含一个类 License 带有静态变量。
所以这将是通用项目的结构:
MyProject.Common (dll)
| -> Serials.Licensing (namespace)
| -> License (class with static variables)
使用 IlMerge,我将这个程序集合并到两个不同的程序集(A.dll、B.dll)中。这将是使用 IlMerge 创建的 2 个程序集的结果:
assemblyA (dll)
| -> Serials.Licensing (namespace)
| -> License (class with static variables)
| class "classA" using the License class of this dll
和
assemblyB (dll)
| -> Serials.Licensing (namespace)
| -> License (class with static variables)
| class "classB" using the License class of this dll
如您所见,两个程序集都有使用 License 类的类(classA,classB)合并到它们自己的程序集中
如果在一个新项目(projectC)中,我同时引用了dll A和dll B,类License中的静态变量会不会有问题(比如冲突)?
我很困惑,因为我不知道 dll A 和 dll B 是否都有自己的“上下文”,或者是否会出现问题,因为命名空间和类型与 License 类的静态变量相同。
最佳答案
如果您尝试访问该类型中的某些内容,您将收到一个编译错误,告诉您该类型 License 存在于 A.dll 和 B.dll 中。所以这对你不起作用。 如果您从不访问该类型,项目应该可以正常编译。
关于另一个引用的不同合并程序集中的 C# 相同类型和命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22500799/