编译使用非特定所需版本的第 3 方供应商组件的 .NET 组件
如果有人要开发依赖于供应商 DLL 的非特定版本的 .NET 组件 - 假设它与 My3rdPartyComponent.dll(它是 .NET 程序集)一起工作,但哪个版本并不重要。
在此组件中找到的一些类实例需要传递到我的组件中。开发人员可以引用我的组件 dll,但无法访问源代码。
基本上,我希望能够要求用户将 3rdPartyComponent.MyClass 的实例传递给我的组件函数,但我不关心它是否是第 3 方 dll 的版本 1.1、2.2、2.23.980 等。
有没有办法在输入我想要传递给组件的参数的同时执行此操作?我不想使用 Object 作为参考。
在我的组件项目中,我可以在程序集引用上指定 SpecificVersion=True。这会解决我的问题还是还会有其他我没有看到的“dll hell”问题需要处理?
If someone were to develop a .NET component that relied on non specific versions of a vendor DLL - let's say it worked with My3rdPartyComponent.dll which is a .NET assembly, but it didn't matter which version.
Some instances of classes found in this component would need to be passed into my component. Developers would reference my component dll but not have access to the source code.
Basically, I want to be able to require the user to pass in an instance of 3rdPartyComponent.MyClass to my component functions but I do not care if it's version 1.1, 2.2, 2.23.980, etc of the 3rd party dll.
Is there a way to do this while still typing the parameter I want to be passed in to my component? I don't want to use Object as the reference.
In my component project I could specify SpecificVersion=True on the assembly reference. Will this solve my problem or will there be other 'dll hell' issues to deal with that I am not seeing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本质上,不,你不能做你想做的事(至少据我所知)。 .NET 版本控制的整个前提是程序集的不同版本是不同的程序集。因此,就 .NET 而言,
3rdPartyComponent.MyClass
版本 1.1 与3rdPartyComponent.MyClass
版本 1.1.1 是完全不同的类。无论好坏,这就是它的运作方式。如果您无法控制第三方程序集,那么支持此操作的唯一方法是使用反射。 .NET 4 中的
dynamic
类型应该使它相当容易 - 但它仍然是一个 hack,并且如果接口发生最轻微的变化就会失败(当然,这就是版本控制的全部要点)。如果您对该程序集有一定的控制权,则可以将一些接口提取到一个单独的程序集中,该程序集很少有任何重大更改,因此其版本几乎永远不会更改。然后,您可以引用该程序集中的接口而不是具体的类。
Essentially, no, you cannot do what you want (at least not to my knowledge). The entire premise of .NET versioning is that different versions of an assembly are different assemblies. So
3rdPartyComponent.MyClass
version 1.1 is a completely different class from3rdPartyComponent.MyClass
version 1.1.1 as far as .NET is concerned. For better or for worse, that is how it works.If you have no control over the third party assembly then the only way you could support this is using Reflection. The
dynamic
type in .NET 4 should make it fairly easy - but it's still a hack and will fail if the interface changes in the slightest way (which is, of course, the whole point of versioning).If you had some control over that assembly you could extract some interfaces into a separate assembly that rarely has any breaking changes, so its version almost never changes. You could then reference the interfaces from that assembly instead of concrete classes.