C#从不同的文件夹加载DLL? [英] C# load DLL from different folder?

查看:41
本文介绍了C#从不同的文件夹加载DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# 项目,其中包含 1 个 EXE 和大约 7 个 DLL.我想要的是 EXE 旁边的一个名为Library"(或类似的东西)的文件夹,其中包含所有 DLL,以便它更有条理,对最终用户来说看起来更好.

I have a C# project that contains 1 EXE and about 7 DLLs. What I would like to have is a folder beside the EXE called "Library" (or something similar) that contains all the DLLs so that it is a bit more organized and looks better for the end user.

我知道这可以使用 AppConfig 来完成,但我不想要 EXE 旁边的另一个文件.我想要的只是主 EXE 和文件夹.

I know this can be done using an AppConfig but the I don't want another file beside the EXE. All I want is the main EXE and the folder.

是否可以使用 AppConfig 并嵌入它或加载 DLL,而无需使用不会改变我当前使用 DLL 的方式的 AppConfig?我知道您可以在运行时加载 DLL,但我认为这不是我想要的.

Is it possible to use AppConfig and embed it or load the DLLs without using a AppConfig that won't change how I currently use my DLLs? I know you can load a DLL at run time but I don't think that is what I am looking for.

谢谢!

编辑

我知道这样做的利弊,所以请只回答如何做到这一点,而没有关于我为什么应该或不应该这样做的建议.

I know the pros and cons to doing this, so please only answers on how to do this and no advice as to why I should or should not do this.

推荐答案

使用 <代码>System.Reflection.Assembly.LoadFrom(path).

LoadFrom 将允许它在与目标 dll 相同的文件夹中查找任何依赖项.如果您使用 Load,那么它不会考虑与您加载的 dll 位于同一文件夹中的 dll.

LoadFrom will allow it to look in the same folder as the targetted dll for any dependencies. If you use Load, then it will not consider dlls that are sitting in the same folder as the dll you Load.

我知道这并不能直接回答您的问题,但是如果您想要一个xcopy"可安装的 .net 应用程序或其他东西,在进程启动的早期手动调用 DLL 上的 LoadFrom 应该可以解决问题.

I know this doesn't directly answer your question, but manually calling LoadFrom on the DLLs early in your process startup should do the trick if you want an "xcopy" installable .net app or something.

这篇关于C#从不同的文件夹加载DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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