更新时间:2023-01-13 14:02:54
AppDomain.CurrentDomain.BaseDirectory
是我去这样做的方式。
不过:
Application.StartupPath
得到您的可执行文件的目录
AppDomain.BaseDirectory
获取用于解决组件目录
由于它们可以是不同的,也许你想使用Application.StartupPath,除非你关心大会决议。
I need to get all dlls in my application root directory. What is the best way to do that?
string root = Application.StartupPath;
Or,
string root = new FileInfo(Assembly.GetExecutingAssembly().Location).FullName;
And after that,
Directory.GetFiles(root, "*.dll");
Which way is better? Are there better ways?
AppDomain.CurrentDomain.BaseDirectory
is my go to way of doing so.
However:
Application.StartupPath
gets the directory of your executable
AppDomain.BaseDirectory
gets the directory used to resolve assemblies
Since they can be different, perhaps you want to use Application.StartupPath, unless you care about assembly resolution.