【问题标题】:XML file present in visual Studio Azure Function Solution Not getting published to AzureVisual Studio Azure Function 解决方案中存在的 XML 文件未发布到 Azure
【发布时间】:2019-09-24 12:35:11
【问题描述】:

我创建了一个从 xml 文件读取数据的 Azure 函数。在本地,一切正常。当我将项目发布到 Azure 时,Azure 日志中出现以下错误。

找不到文件 'D:\Windows\system32\xxxx.xml

当我检查 Azure 上的 wwwroot 目录时,该文件在那里不可用。请告诉我如何将此 xml 文件发布到 Azure?

【问题讨论】:

    标签: visual-studio-2017 azure-functions publish


    【解决方案1】:

    确保在“复制到输出”部分中将 xml 文件设置为“始终复制”:

    要在函数中实际读取该文件,您需要首先获取当前的函数工作目录。这是通过获取ExecutionContext 来完成的,如下所示:

    public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ExecutionContext context)
    {
        var filePath = Path.Combine(context.FunctionAppDirectory, "XMLFile1.xml");
    }
    

    【讨论】:

    • 谢谢....它工作了,现在文件被复制到 wwwroot 文件夹。但现在我遇到了另一个错误。 System.IO.FileNotFoundException:找不到文件“D:\Windows\system32\xxxx.xml”。虽然文件放在 wwwroot 文件夹中
    • 查看我对答案的补充
    • 很高兴听到它
    猜你喜欢
    • 2016-01-13
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多