我需要执行程序集的bin路径。你怎么得到的?我在Bin / Debug中有一个文件夹Plugins,我需要获取位置
Answers:
这是获取应用程序执行路径的方法:
var path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
MSDN有关如何确定执行应用程序的路径的完整参考。
请注意,中的值path将采用的形式file:\c:\path\to\bin\folder,因此在使用路径之前,您可能需要先file:\去除前部。例如:
path = path.Substring(6);
你可以这样做
Assembly asm = Assembly.GetExecutingAssembly();
string path = System.IO.Path.GetDirectoryName(asm.Location);
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
这是我用来完成此任务的:
System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.RelativeSearchPath ?? "");
RelativeSearchPath中包含实际的“bin”文件夹并在控制台应用程序,这是null与BaseDirectory包含实际的“bin”的路径。
Path.GetDirectoryName(Application.ExecutablePath)
例如。值:
C:\Projects\ConsoleApplication1\bin\Debug