捕获 dll 加载

发布于 2024-10-08 22:32:10 字数 508 浏览 4 评论 0原文

我正在尝试构建一个 .NET 客户端软件包,可以按需下载其组件。

假设我有一个程序,它分为一个主可执行文件和 20 个其他 dll 文件。主程序引用了其中的 3 个,它们引用了其他一些,无论如何......它们有某种类似树的依赖结构。

我想要实现的目标是仅分发主要可执行文件,并按需从服务器位置获取其他所有内容。

像这样的东西: 主程序和所有这些 dll 项目都在一个解决方案中,并且像任何其他解决方案一样构建在一起。 分发时,仅分发 exe,其他 dll(包括使用的一些第三方库)放在可供下载的服务器位置。

exe运行,显示一些UI,当用户单击菜单项时,将显示dll文件中的另一个UI窗口,以便操作系统查找dll(不存在),我介入,从下载所需的dll服务器,将其放在 exe 旁边,让操作系统加载它,就好像它从一开始就在那里一样。

这看起来可以通过使用通用接口类和一些反射魔法来实现,但我希望有更多的东西,包括在单个解决方案中完全构建 dll,包括按需下载第 3 方库。

有什么想法如何做到这一点?

I am trying to build a .NET client software package that downloads its components on demand.

Let's say I have a program that is split into a main executable and 20 other dll files. The main program references 3 of them, they reference some others, anyway... they have some kind of tree like dependency structure.

The thing I am trying to achieve is to distribute just the main executable and get everything else from a server location on-demand.

Something like this:
The main program and all these dll projects are in a single solution and are built together just like any other solution.
While distributing, only the exe is distributed, the other dll's (including some third party libraries used) are put in a server location available for download.

The exe runs, shows some UI, when the user clicks a menu item, another UI window from one the dll files is to be shown so the OS looks for the dll (which is not there), I intervene, download the required dll from the server, put it next to the exe and let the OS load it as if it was there from the very beginning.

This looks achievable by the use of a common Interface class and some reflection magic but I was hoping for something more, something that includes building the dll's altogether in a single solution, something that includes the on-demand download of 3rd party libraries.

Any ideas how to do this?

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

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

发布评论

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

评论(3

懒的傷心 2024-10-15 22:32:10

您正在寻找 AppDomain.AssemblyResolve 事件,它允许您从自定义位置加载程序集。
你不需要任何其他的反思。

You're looking for the AppDomain.AssemblyResolve event, which allows you to load assemblies from custom locations.
You won't need any other reflection.

丿*梦醉红颜 2024-10-15 22:32:10

为当前应用程序域的 AppDomain.ResolveAssembly 和 AppDomain.ResolveType 事件提供事件处理程序并加载程序集。

但请小心将程序集加载到正确的上下文中: http://msdn.microsoft .com/en-us/library/dd153782.aspx

Provide event handlers for AppDomain.ResolveAssembly and AppDomain.ResolveType events for your current appdomain and load the assemblies.

But be careful to load the assemblies into the right context: http://msdn.microsoft.com/en-us/library/dd153782.aspx

小傻瓜 2024-10-15 22:32:10

您可以捕获在未找到程序集时触发的 AssemblyResolve 事件,然后下载它尝试查找的程序集。

您应该阅读这篇文章。

You can cath the AssemblyResolve event, that fires when an assembly is not found, and then download the assembly it tries to find.

You should read this article.

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