C# 获取当前的 dll 所在的路径
public static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
- 通过
CodeBase得到一个 URI 格式的路径; - 用
UriBuild.UnescapeDataString去掉前缀 File://; - 用
GetDirectoryName把它变成正常的 windows 格式。
转自:https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in
本文介绍了一种在C#中获取当前DLL文件所在路径的方法。通过使用Assembly.GetExecutingAssembly()来获取当前执行程序集的信息,并进一步解析其CodeBase属性得到路径。
975

被折叠的 条评论
为什么被折叠?



