我知道,在我的code正在执行一些文件所在的同一目录中。我需要找到他们,并传递给另一种方法:
I know that in the same directory where my code is being executed some files are located. I need to find them and pass to another method:
MyLib.dll
Target1.dll
Target2.dll
Foo(new[] { "..\\..\\Target1.dll", "..\\..\\Target2.dll" });
于是我打电话 System.IO.Directory.GetFiles(路径,* .dll文件)
。但现在我需要知道路径:
So I call System.IO.Directory.GetFiles(path, "*.dll")
. But now I need to get know the path:
string path = new FileInfo((Assembly.GetExecutingAssembly().Location)).Directory.FullName)
但有更短的路?
but is there more short way?
您可以尝试的Environment.CurrentDirectory属性。请注意,根据应用程序的类型(控制台,的WinForms,ASP.NET,Windows服务,...)和它的方式运行,这可能表现不同。
You may try the Environment.CurrentDirectory
property. Note that depending on the type of application (Console, WinForms, ASP.NET, Windows Service, ...) and the way it is run this might behave differently.