确定装配位置
我有一个名为 A 的项目,位于 C:\ProjectA。 它引用了一个名为 B.dll 的 dll,位于 C:\Binaries 中。
现在 B.dll 必须动态加载第二个名为 C.DLL 的 DLL,它位于同一文件夹 (C:\Binaries) 中。但B如何确定C的位置呢?
我知道 AppDomain.CurrentDomain.BaseDirectory 和 Assembly.GetExecutingAssembly().Location,但两者都会返回“C:\ProjectA\”,因为 B.dll 是由 A.exe 加载的。
我知道明显的解决方案是将所有二进制文件放在同一个文件夹中,并且它们将在发布时发布,但是在开发时我无法更改存储库的布局,并且我想避免对路径进行硬编码。
编辑:抱歉重复 如何获取代码所在程序集的路径?
I have project called A, located in C:\ProjectA.
It references a dll called B.dll, located in C:\Binaries.
Now B.dll has to dynamicly load a second DLL called C.DLL which is in the same folder (C:\Binaries). But how can B determine C's location?
I know about AppDomain.CurrentDomain.BaseDirectory and Assembly.GetExecutingAssembly().Location, but both will return 'C:\ProjectA\', because B.dll was loaded by A.exe.
I know the obvious solution would be to place all binaries in the same folder, and they will be when released, but while developing I cannot change the repositry's layout, and I want to avoid to hardcode the paths.
Edit: Sorry duplicate of How do I get the path of the assembly the code is in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 MSDN ,您必须根据关于 C(或 B)中存在的某种类型:
From MSDN, you have to test it based on some type existing in C (or B):
如何使用
Assembly.GetCallingAssembly
来自 B?这将返回调用当前正在执行的方法的方法的 Assembly 对象。 (即B)另请参见这个类似的堆栈溢出问题
How about using
Assembly.GetCallingAssembly
from B? This will return The Assembly object of the method that invoked the currently executing method. (ie B)see also this similar stack overflow question