Tôi thấy rằng có một số cách để có được đường dẫn thư mục ứng dụng:
Application.StartupPathSystem.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)AppDomain.CurrentDomain.BaseDirectorySystem.IO.Directory.GetCurrentDirectory()Environment.CurrentDirectorySystem.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)System.IO.Path.GetDirectory(Application.ExecutablePath)
Cách tốt nhất tùy thuộc vào tình huống là gì?
IHostEnvironment.ContentRootPath, được truy cập thông qua một IHostEnvironmentphụ thuộc được tiêm (có chứa những thứ hữu ích khác).