英文:
Get the path to a directory in an AWS .NET 6 Lambda deployed via GitHub Actions
问题
我正在通过GitHub Actions部署AWS .NET 6 Lambda。函数处理程序需要读取一堆文本文件。文件夹结构如下:
text-files
file1.txt
file2.txt
...
Program.cs(处理程序在此)
MyFunction.csproj
我正在尝试获取text-files
的路径,但这样做失败了:
var directoryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "text-files");
// var directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "text-files");
// var directoryPath = Path.Combine(Environment.GetEnvironmentVariable("LAMBDA_TASK_ROOT"), "text-files");
当我打印directoryPath
的值时,所有上述方法都返回:
/var/task/text-files
这会失败,因为上述路径不存在。获取text-files
路径的正确方法是什么,以便我可以读取该文件夹中的每个文件?
英文:
I'm deploying an AWS .NET 6 Lambda via GitHub Actions. The function handler needs to read a bunch of text files. The folder structure looks like this:
text-files
file1.txt
file2.txt
...
Program.cs (handler is here)
MyFunction.csproj
I'm trying to get the path to text-files
, but this is failing:
var directoryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "text-files");
// var directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "text-files");
// var directoryPath = Path.Combine(Environment.GetEnvironmentVariable("LAMBDA_TASK_ROOT"), "text-files");
When I print out the value for directoryPath
, all approaches above return:
/var/task/text-files
This fails because the above path does not exist. What's the right way to get the path to text-files
so I can read each file in that folder?
答案1
得分: 1
使用IHostEnvironment.ContentRootPath
获取应用程序的根路径,然后从那里构建您的路径。
英文:
Use IHostEnvironment.ContentRootPath
to get the root path of your application and then construct your path from there.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论