装载组件

发布于 2024-08-08 09:28:35 字数 595 浏览 2 评论 0原文

有很多讨论展示了如何从 BIN 和 GAC 加载程序集...我的问题更笼统,我很想知道程序集加载是如何工作的。

例如,

在 BIN 文件夹中,我们可以有

A.dll
A.dll.config 

A.dll.config 文件,如下所示:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

帮助我们设置正确的程序集引用。

我想知道如何创建需要 B.dll 但不指定任何版本的 A.dll,以便始终采用 BIN 文件夹中的 B.dll。

我的问题是关于 SDK 的更新,我的所有代码仍然指向旧的 SDK 版本,我想让我的程序集查找所有资源版本中最靠前的版本(BIN 或 GAC)并使用该版本...

如何我可以在 Visual Studio 中这么说吗?我只能添加对物理文件(版本)的引用:-(

There are plenty of discussing that shows how to load assemblies from BIN and from GAC... my question is more general and I would love to know how assembly loading work.

As for example

in the BIN folder we can have

A.dll
A.dll.config 

A.dll.config file can look like:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

to help us setting the correct assembly reference.

I was wondering how can I create a A.dll that needs B.dll but without specify any version so if would always take the B.dll that is in the BIN Folder.

My question is regarding an update of the SDK and all my code still points to the old SDK version, I wanted to have my assembly look for the top most of all versions of the resource, BIN or GAC and use that one...

How can I say that in Visual Studio? I can only Add Reference to a physical file (version) :-(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断桥再见 2024-08-15 09:28:35

如果我理解正确,我想您可以使用“插件”方式通过 AppDomain 对象执行操作。也许通过AppDomain加载程序集,因为您可以设置加载的程序集的路径,所以您将能够轻松地替换文件,卸载程序集并在ShadowCopy中重新加载新程序集。 ShadowCopy 允许您将最新文件复制到当前文件程序集的同一位置。然后,构建检查新文件的机制,如果存在,则卸载程序集并重新加载最新文件。这样,一切对于您的程序来说都将非常透明,尽管它需要您进行更多的编程。尽管如此,您仍将获得长期发展。

If I understand correctly, I guess you could use the "plugins" way of doing things through the AppDomain object. Perhaps loading the assembly through the AppDomain, since you can set the path for the loaded assembly, you will be able to easily replace the files, unload the assembly and reload the new one in ShadowCopy. The ShadowCopy allows you to copy the latest file at the same location of the current file assembly. Then, build your mechanism to check for a new file, and if it exists, then unload your assembly and reload the latest. This way, everything will be quite transparent for your program, though it requires a bit more programming from your side. Nevertheless, you will gain in long term development.

岁月静好 2024-08-15 09:28:35

您可以使用后期绑定和反射。有很多地方可以阅读有关此内容的内容,但您可以从 这里

You can use late binding and Reflection. There are many places to read about this, but you can start here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文