如何知道dll的路径

tsys2000 2011-09-04 11:46:20
程序内引用了一个dll,如何在运行时,知道这个dll的路径?
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
LMAOhuaNL 2011-09-05
  • 打赏
  • 举报
回复
遥望那些年 2011-09-05
  • 打赏
  • 举报
回复
Assembly.GetExecutingAssembly().Location
tsys2000 2011-09-05
  • 打赏
  • 举报
回复
谢谢楼上。
但上面我以前也试过,得到的路径和
ClassLib1 c = new ClassLib1();
c.GetType().Assembly.Location;
是一样。
和ide引用的属相上看到的那个路径不同。
lichliu 2011-09-05
  • 打赏
  • 举报
回复
public static string GetDllPath()
{
string dllPath = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
dllPath = dllPath.Replace("file:///", "").Replace("/", "\\");
int index = dllPath.LastIndexOf("\\");
dllPath = dllPath.Substring(0, index + 1);
return dllPath;
}
tsys2000 2011-09-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lmaohuanl 的回复:]

答案
[/Quote]

这个应该是exe的路径。不是dll的。
用下面方式得到的路径,与在ide中引用的属相上看到的路径不同,怎么得到在ide引用的属相上看到的那个路径?
ClassLib1 c = new ClassLib1();
c.GetType().Assembly.Location;

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧