简体   繁体   English

如何处理第三方.Net程序集的新版本而无需重新编译?

[英]How to handle new releases of third-party .Net assemblies without recompiling?

I have some projects that rely on external .Net assemblies to operate. 我有一些依赖外部.Net程序集进行操作的项目。 These are installed externally from my program so I do not have direct control over what version is being used. 这些都是从我的程序外部安装的,因此我无法直接控制所使用的版本。 Furthermore, updates are expected to be installed as a matter of course. 此外,理所当然地希望安装更新。

For example, in one case I am accessing a hardware device that provides a .Net interface to control it. 例如,在一种情况下,我正在访问提供.Net接口来控制它的硬件设备。 When the user initially installs the device, they install the driver that is included. 用户最初安装设备时,他们将安装随附的驱动程序。 This driver when I wrote the program may have been 3.0.4.0. 我写程序时的驱动程序可能是3.0.4.0。 The latest version might be 3.1.8.0. 最新版本可能是3.1.8.0。

My program fails to load the assembly when this happens complaining that the manifest definition is incorrect. 抱怨清单定义不正确时,我的程序无法加载程序集。 A specific exception message is show below. 特定的异常消息如下所示。

Another example is a labeling program. 另一个示例是标签程序。 They provide a .Net interface to allow my program to print labels through their system. 他们提供了.Net界面,允许我的程序通过其系统打印标签。 Installing an updated version of the program is fatal. 安装程序的更新版本是致命的。

Here is the specific exception message: 这是特定的异常消息:

Could not load file or assembly 'SDK.NET.Interface, Version=17.1.0.0,
Culture=neutral, PublicKeyToken=865eaf3445b2ea56' or one of its
dependencies. The located assembly's manifest definition does not match
the assembly reference.

If I install this version of the application on my computer, then reference the updated version of the assembly and compile, I'm good to go . 如果我在计算机上安装了此版本的应用程序,然后引用该程序集的更新版本并进行编译,那么我很好。 . . for now. 目前。

But, it's only a matter of time before I will have the issue again. 但是,再次提出问题只是时间问题。

I've tried setting the Specific Version property of the referenced assemblies to False but that didn't affect the problem. 我尝试将引用程序集的“ Specific Version属性设置为False但这并不影响问题。

What is the proper way to address the issue? 解决该问题的正确方法是什么?

You are able to "Plug and Play" as long as method signatures don't change. 只要方法签名不变,您就可以“即插即用”。

If those change, then you'll need to fix your base code. 如果这些更改,那么您将需要修复您的基本代码。

Look at Microsoft's documentation on Redirecting Assembly Versions: http://msdn.microsoft.com/en-us/library/7wd6ex19%28VS.71%29.aspx 查看有关重定向程序集版本的Microsoft文档: http : //msdn.microsoft.com/zh-cn/library/7wd6ex19%28VS.71%29.aspx

Another option is If these libraries are somehow controlled by you or your company, you might have some wiggle room with reflection by loading them up by their base type/interface and using common methods... but you'll need to have access to the base types. 另一个选择是,如果这些库由您或您的公司以某种方式控制,则可能需要一些反射空间,方法是通过它们的基本类型/接口并使用常见方法来加载它们,但是您需要访问基本类型。

This is also a duplicate question: 这也是一个重复的问题:

Upgrade a reference dll in a C# project without recompiling the project 在C#项目中升级参考dll,而无需重新编译项目

Upgrading dependent DLL without recompiling the whole application 升级依赖的DLL,而无需重新编译整个应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理第三方代码中的死锁 - How to handle a deadlock in third-party code 如何在我的客户端应用程序中处理第三方站点上的recaptcha - How to handle recaptcha on third-party site in my client application 如何在不安装的情况下使用第三方 DLL - How to use third-party DLL without installing it 如何在.NET中导入第三方IronPython模块? - How do I import a third-party IronPython module in .NET? .NET如何判断安装的驱动是不是第三方驱动? - How to determine if a installed driver it's a third-party driver in .NET? SSIS 2017 和第三方 .NET 组件 - SSIS 2017 and Third Party .NET Assemblies 如何配置第三方dll中的资源? - How to dispose resources in third-party dll? 使用OWIN和第三方系统在ASP.NET MVC 5中进行身份验证而不存储凭据 - Authenticating in ASP.NET MVC 5 with OWIN and Third-Party system without storing credentials 在不使用免费的第三方解决方案的情况下在ASP.NET中压缩文件 - Zipping files in ASP.NET without using free third-party solutions 如何处理包装第三方长期运行方法的任务的取消 - How to handle cancellation on Task that wraping a third-party long running method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM