我的项目具有以下文件夹结构:
- 项目,
- 项目/数据
- 项目/引擎
- 项目/服务器
- 项目/前端
在服务器中(在Project / Server文件夹中运行),我指的是这样的文件夹:
var rootFolder = Directory.GetCurrentDirectory();
rootFolder = rootFolder.Substring(0,
rootFolder.IndexOf(@"\Project\", StringComparison.Ordinal) + @"\Project\".Length);
PathToData = Path.GetFullPath(Path.Combine(rootFolder, "Data"));
var Parser = Parser();
var d = new FileStream(Path.Combine(PathToData, $"{dataFileName}.txt"), FileMode.Open);
var fs = new StreamReader(d, Encoding.UTF8);
在我的Windows机器上,此代码可以正常工作,因为已Directory.GetCurrentDirectory()
转至当前文件夹,并且可以
rootFolder.Substring(0, rootFolder.IndexOf(@"\Project\", StringComparison.Ordinal) + @"\Project\".Length);
获取我项目的根文件夹(不是bin或debug文件夹)。但是,当我在Mac上运行它时,它却把Directory.GetCurrentDirectory()
我发送到/ usr // [其他]。它没有指向我的项目所在的文件夹。
在项目中查找相对路径的正确方法是什么?我应该将数据文件夹存储在解决方案中的所有子项目(特别是kestrel服务器项目)易于访问的地方吗?我宁愿不必将其存储在wwwroot文件夹中,因为数据文件夹是由团队中的其他成员维护的,而我只想访问最新版本。我有什么选择?