我看到有几种方法可以获取应用程序文件夹路径:
Application.StartupPath
System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)
AppDomain.CurrentDomain.BaseDirectory
System.IO.Directory.GetCurrentDirectory()
Environment.CurrentDirectory
System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
System.IO.Path.GetDirectory(Application.ExecutablePath)
根据不同情况,哪种方法是最好的呢?
IHostEnvironment.ContentRootPath
,通过注入的IHostEnvironment
依赖项进行访问(其中包含其他有用的内容)。 - TimoProcess.GetCurrentProcess().MainModule.FileName
。 - nawfal