[英]How to get current physical path of a reflected assembly
I have an executable that loads another class library DLL using reflection. 我有一个可执行文件,可以使用反射加载另一个类库DLL。 Within that class library, I want to find out what the physical path of the class library is.
在该类库中,我想找出类库的物理路径是什么。 I don't want the executing assembly, as that is the original executable.
我不需要执行程序集,因为那是原始可执行文件。
Eg the exe might be in c:\\program\\ and the class library might be c:\\libraries\\remote\\Assembly1.dll 例如,exe可能在c:\\ program \\中,而类库可能在c:\\ libraries \\ remote \\ Assembly1.dll中
Within a method inside Assembly1.dll I need to call something that returns me 在Assembly1.dll内部的方法中,我需要调用返回我的东西
c:\\libraries\\remote\\
c:\\ libraries \\ remote \\
I have tried 我努力了
var currentLocation = Assembly.GetAssembly(GetType()).Location;
But that doesn't seem to work. 但这似乎不起作用。 How can I do this?
我怎样才能做到这一点?
我使用这种方法来获取当前类的汇编路径:
var dllPath = new Uri(this.GetType().Assembly.GetName().CodeBase).LocalPath;
Here's one way I do it. 这是我做到的一种方式。 "assembly" is the loaded dll
“程序集”是已加载的dll
assembly.Location.Replace(assembly.GetName().Name + ".dll", "")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.