.net 5.0 - 获取路径

var path = Directory.GetCurrentDirectory();//获取当前的项目文件所在的目录。当使用命令启动时为执行dotnet命令所在的目录

dynamic type = (new Program()).GetType();
string currentDirectory = Path.GetDirectoryName(type.Assembly.Location);//获取应用程序的当前目录,即代码生成的dll文件所在目录

string contentRootPath = _env.ContentRootPath;//获取当前项目所在的文件夹

  

posted @ 2021-04-13 22:55  gygtech  Views(460)  Comments(0Edit  收藏  举报