我的项目的文件夹结构如下:
In the server (running in the Project/Server folder) I refer to the folder like this:
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 或调试文件夹)。
但是当我在 Mac 上运行它时,它被“ Directory.GetCurrentDirectory()
”发送到/usr//[ something else ]。它没有引用我的项目所在的文件夹。
What is the correct way to find relative paths in my project? Where should I store the data folder in a way that it is easily accessible to all the sub projects in the solution - specifically to the kestrel server project? I prefer to not have to store it in the wwwroot folder because the data folder is maintained by a different member in the team, and I just want to access the latest version. What are my options?