简体   繁体   English

在运行时解析第三方dll路径

[英]Resolve 3rd party dll path at runtime

I'm developing an application that depends on some 3rd party dll's (it's actually a plugin to the 3rd party application, and I receive COM objects implementing certain interfaces declared in those dll's). 我正在开发依赖于某些第三方dll的应用程序(它实际上是第三方应用程序的插件,并且我收到实现在那些dll中声明的某些接口的COM对象)。 My project contains references to those dll's locally exist on the dev machine, but I want to avoid wraping them inside my installer (for size and legal considerations). 我的项目包含对那些在开发机器上本地存在的dll的引用,但是我想避免将它们包装在我的安装程序中(出于大小和法律考虑)。

Instead, my installer requires that the dll's are already existing on the target machine, and their path is saved to a text file next to my executable assembly. 相反,我的安装程序要求目标计算机上已经存在dll,并且它们的路径保存到我的可执行程序集旁边的文本文件中。

How can I use this file to link to the dll's on run time? 如何使用此文件链接到dll的运行时?
Or is it better to add an environment variable during installation and use it instead (how can it be done)? 还是在安装过程中添加环境变量并改而使用它(如何完成)更好?

Using project references, I do not know of a way to have dlls in an arbitrary location. 使用项目引用,我不知道在任意位置具有dll的方法。 Typically I've handled this issue using an installer, like InstallAware, prompted the user for the 3rd party location, and copied the dlls into my projects folder at the same relative location I chose in my solution file. 通常,我已经使用安装程序(如InstallAware)处理了此问题,并提示用户输入第三者的位置,并将dll复制到了我在解决方案文件中选择的相同相对位置的项目文件夹中。

If this is improbable for you, you can always load the dlls and create instances of the classes yourself by hand using Assembly.LoadFrom and Activator.CreateInstance . 如果这对您来说是不可能的,则始终可以使用Assembly.LoadFromActivator.CreateInstance手动加载dll并手动创建类的实例。

I hope this helps. 我希望这有帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM