.net - Azure Functions 在 bin 内创建另一个 bin 文件夹

标签 .net azure dll visual-studio-2017 azure-functions

我在使用 Azure 函数时遇到问题,看到 bin 内创建了另一个 bin 文件夹。所以文件夹结构就像这样 bin -> net461 -> bin -> dll。但是,项目中的任何其他文件(json、xml)都会被复制到 bin -> net461 。由于这种引用文件(json,xml)在代码中变得困难。我不需要另一个 bin 文件夹。如何解决这个问题?

最佳答案

I try to read the file something like this File.ReadAllText(@"FolderName\FileName.json") but when function executes it gives error - Could not find a part of the path 'D:\Windows\system32\FolderName\FileName.json'.

我检查了这个问题,发现您的代码可以在本地正确运行,但在部署到azure端后失败。您可能需要显式设置绝对路径来读取 json 文件。您可以利用 Microsoft.Azure.WebJobs.ExecutionContext.FunctionDirectory 获取当前函数目录(例如 D:\home\site\wwwroot\<FunctionName> 表示 Azure 端, C:\Users\xxx\FunctionApps\bin\Debug\net461\<FunctionName> 表示本地端)。详情可关注Retrieving information about the currently running function .

读取 json 文件的代码如下所示:

File.ReadAllText(Path.Combine(Directory.GetParent(executionContext.FunctionDirectory).FullName,@"helloworld.json"));

此外,你可以关注这个github issue还有这个tutorial .

关于.net - Azure Functions 在 bin 内创建另一个 bin 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50302293/

相关文章:

c# - 带有文件的盒子,从 Windows 中看不到

c# - C# .NET 的 Flickr API 始终返回 100 张图片

C# 变量初始化与赋值

.net - 在 .NET 中调试依赖注入(inject)

azure - terraform 显示返回 4 个 json 对象

c# - 当我尝试使用服务总线触发功能时,收到错误消息 "Cannot convert input parameter",为什么?

asp.net-mvc - 构建面向完整 .net 框架的 VS2017 .net core 应用程序

dll - Haskell编译dll

c++ - 奇怪的#include 问题

c - Windows 上混合 Julia 和 C 项目的最小工作示例