使用 XCOPY 部署动态加载程序集及其依赖项
我有一个动态加载应用程序的应用程序加载器。 应用程序是一个程序集,其所有依赖项都位于一个文件夹中。 使用 XCOPY 部署,我可以通过复制/删除文件夹来添加/删除应用程序。 为了促进标准 .NET 程序集绑定,我将应用程序文件夹复制到加载程序的 bin 下。 我在配置文件中设置了探测 privatePath,一切都非常顺利。
应用程序使用框架,即共享程序集作为依赖项。
现在我有一个要求,规定每个应用程序都必须能够使用自己的框架版本。
当我在 GAC 中安装框架版本时,这非常有效,并且不同版本的程序集都可以很好地加载到默认的 AppDomain 中。
现在我想返回到我的 XCOPY 解决方案并将正确的框架版本复制到相应的应用程序文件夹中,但解决方案崩溃了。
第一个应用程序引用其框架工作正常,第二个应用程序抱怨找不到程序集且清单不匹配。
就好像 .NET 加载程序在程序集与“privatePath”中的文件夹第一次匹配后停止探测,并且不再进一步查找。
关于如何实现与使用 GAC 时相同的行为有什么想法吗? 我还可以在配置、代码库中指定什么吗? (请不要绝对文件路径)。
克尔, 米歇尔
I have an application loader that dynamically loads applications.
An application is an assembly with all of its dependents in a single folder.
Using XCOPY deployment I can add/remove applications by copying/deleting a folder.
To facilitate standard .NET assembly binding I copy the application folders under the bin of the loader.
I set the probing privatePath in the config file and everything works like a charm.
The applications uses a framework, i.e. shared assemblies as dependents.
Now I have a requirement that states that each application has to be able to use its own version of the framework.
This works perfectly when I install the framework versions in the GAC, and the different versions of the assembly are loaded into the default AppDomain just fine.
Now I want to get back to my XCOPY solution and copy the correct framework versions in their corresponding application folders and the solution breaks.
The first application referencing its framework works fine, the second complains about not finding the assembly and the manifests not matching.
It's as if the .NET loader stops probing after a first match of the assembly with a folder in "privatePath" and does not look any further.
Any ideas on how to have the same behavior as when using the GAC?
Anything else I could specify in config, codeBase? (no absolute file paths please).
kr,
Michel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据这篇关于程序集的文章:
更新:
查看这篇文章。它或多或少地解决您遇到的相同问题。
According to this article on Assemblies:
Update:
Check this post. It deals with more or less the same problem you're having.
如果您使用 Assembly.LoadFrom 加载在这些文件夹中找到的所有程序集,您会更幸运。
这会改变探测行为,并允许运行时在本地搜索程序集最初加载的位置,以便找到其引用。不过,您将在程序集级别获得框架版本共享。
即:
也就是说,如果您没有显式加载程序集,则此解决方案可能没有用。
在这种情况下 - 我会采用 Yannick M. 提到的答案中的解决方案 - 挂钩到 AssemblyResolve 事件;当您开始加载应用程序时存储一些静态状态,以便您的事件处理程序知道正在加载哪个应用程序;如果任何程序集无法解析,您可以查看此状态以确定它应该在哪里查找并从那里加载程序集。
You will have more luck if you use Assembly.LoadFrom to load all the assemblies you find in these folders.
This changes probing behaviour and allows the runtime to search locally to where the assembly was originally loaded from in order to find its references. You will get framework-version sharing at the assembly level, though.
That is:
that said - this solution might be of no use if you're not explicitly loading the assemblies.
In that case - I'd go with the solution in the answer mentioned by Yannick M. - hook into the AssemblyResolve event; store some static state as you begin to load an app so your event handler knows which app is loading; and if any Assembly fails to resolve, you can look at this state to determine where it should be looking and load the assembly from there.