产品发布更改库名,如何兼容新旧?
我们有一个产品使用来自第三方供应商的参考。 随着新产品的发布,他们已将此参考重新命名为新名称。
我们想要做的是编译应用程序的一个版本,以便它可以针对库的旧名称和新名称运行。
我们使用的库的各个部分之间基本上没有变化,只有 1 个方法重命名,但我不知道如何开发我们的应用程序来处理这两个部分。
如果必须的话,我们可以对代码进行分支以同时使用两者,但我真的希望有某种适配器,所有调用都经过它,然后分派到旧的或新的。
一旦我安装了新的应用程序,它就会删除旧的库,因此旧的代码将无法编译。
有关我可以尝试什么或如何解决此问题的任何指示吗?
此外,该应用程序是使用 Visual Studio 2005 用 C# 开发的。
We have a product that uses a Reference from a 3rd party supplier. With the release of their new product they have renamed this Reference to a new name.
What we want to do is have the one version of our application compiled so that it can run against both the old and new names of the library.
There is basically no change, only 1 method rename, between the parts of the library we use, but I have no idea how to develop our application to handle both.
If I have to we can branch the code to work with both, but I'd really like to have some sort of adapter that all calls go through that then dispatches to either the old or new.
Once I install the new application, it removes the old library, so the old code won't compile.
Any pointers on what I can try or how I can work around this issue?
Also, the application is developed in C# using Visual Studio 2005.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看程序集绑定重定向< /a>... 您可以将旧的 DLL 引用重定向到新的。 您将需要为重命名的方法编写一个包装方法。这真是令人痛苦。 我会把它从我的脑海中吐出来,所以我不保证名称的准确性或可编译性,但你可以认为它是伪代码......
类似的东西。 无论如何这都不理想。
我很好奇,为什么你不能总是使用新的参考呢? 只需将新的参考 DLL 与您的代码一起分发,您就永远不会遇到问题...
Look at Assembly Binding Redirection... You can redirect the old DLL references to the new one. You will need to write a wrapper method for the renamed method.. That's a real pain in the butt. I'm gonna spitball this off the top of my head, so I don't guarantee name accuracy or compilability, but you can consider it pseudo code...
Something like that. It's not ideal in any case.
I am curious, why can't you just always use the new reference? Just distribute the new reference DLL with your code, and you'll never have an issue...
我建议您执行以下步骤:
在这个单一的内部使用反射类来找出这两种方法中哪一种可用。 缓存实际方法以避免在频繁调用库时造成性能损失。 实际的反射将如下所示:
类型类型 = Type.GetType(alien);
MemberInfo[] mbrInfoArray=type.GetMethods();
该方法将使用 Invoke 来调用。
I would suggest you the following steps:
Use Reflection inside this single class to find out which of the two method is available. Cache the actual method to avoid a performance penalty when you call the library very frequently. The actual reflection will look like this:
Type type = Type.GetType(alien);
MemberInfo[] mbrInfoArray=type.GetMethods();
The method will be called using Invoke.