如何从/bin 目录中加载所有程序集 [英] how to load all assemblies from within your /bin directory

查看:31
本文介绍了如何从/bin 目录中加载所有程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Web 应用程序中,我想加载/bin 目录中的所有程序集.

In a web application, I want to load all assemblies in the /bin directory.

因为它可以安装在文件系统的任何位置,所以我无法保证它的存储路径.

Since this can be installed anywhere in the file system, I can't gaurantee a specific path where it is stored.

我想要一个 List<> 的 Assembly 程序集对象.

I want a List<> of Assembly assembly objects.

推荐答案

好吧,您可以使用以下方法自己破解它,最初使用类似的方法:

Well, you can hack this together yourself with the following methods, initially use something like:

string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

获取当前程序集的路径.接下来,使用带有合适过滤器的 Directory.GetFiles 方法遍历路径中的所有 DLL.您的最终代码应如下所示:

to get the path to your current assembly. Next, iterate over all DLL's in the path using the Directory.GetFiles method with a suitable filter. Your final code should look like:

List<Assembly> allAssemblies = new List<Assembly>();
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

foreach (string dll in Directory.GetFiles(path, "*.dll"))
    allAssemblies.Add(Assembly.LoadFile(dll));

请注意,我尚未对此进行测试,因此您可能需要检查 dll 是否实际包含完整路径(如果不包含则连接路径)

Please note that I haven't tested this so you may need to check that dll actually contains the full path (and concatenate path if it doesn't)

这篇关于如何从/bin 目录中加载所有程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆