我知道在执行我的代码的同一目录中有一些文件。我需要找到它们并传递给另一个方法:
MyLib.dll
Target1.dll
Target2.dll
Foo(new[] { "..\\..\\Target1.dll", "..\\..\\Target2.dll" });
所以我调用 System.IO.Directory.GetFiles(path, "*.dll")
。但现在我需要了解路径:
string path = new FileInfo((Assembly.GetExecutingAssembly().Location)).Directory.FullName)
但是还有更短的路吗?
最佳答案
你可以试试 Environment.CurrentDirectory
属性(property)。请注意,根据应用程序的类型(控制台、WinForms、ASP.NET、Windows 服务等)及其运行方式,这可能会有所不同。
关于c# - 获取执行代码所在的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3271326/