发布Azure函数并使用appsettings.json [英] Publish azure functions and use appsettings.json

查看:122
本文介绍了发布Azure函数并使用appsettings.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure Functions项目,我正在使用Visual Studio 2017 15.3预览版7用C#编写.functions项目包含两个单独的函数,这两个函数都是计时器触发的.我在appsettings.json文件中指定了许多appsettings,该文件设置为复制到内部版本的输出目录.

I have an Azure Functions project, which I am writing in C# using Visual Studio 2017 15.3 preview 7. The functions project contains two seperate functions, both of which are timer triggered. I have a number of appsettings which I have specified in an appsettings.json file, which is set to Copy to the output directory on build.

当我发布Azure Functions项目时,这两个函数会显示在Azure门户中,但是由于无法访问应用程序设置,它们将失败.现在我知道我可以在应用程序设置刀片中指定设置,但是我想使用appsettings.json,这可以根据以下github问题进行: https://github.com/Azure/azure-functions-cli/issues/33

When I publish the Azure Functions project, the two functions are displayed in the Azure portal, however they fail as they do not have access to the app settings. Now I know I can specifiy the settings in the application settings blade, but I want to use appsettings.json which should be possible according to this github issue: https://github.com/Azure/azure-functions-cli/issues/33

此SO答案包含有关使其正常工作的一些信息 Azure函数-使用appsettings.json .现在,问题出在"Azure将尝试将appsettings.json文件查找到要使用的函数的根文件夹中".目前我的功能项目包含以下文件结构:

This SO answer contains some information about getting it to work Azure Functions - using appsettings.json. Now the issue lies in "Azure will try looking for after appsettings.json file into your root folder of the Function that you working on." My function project as it stands contains the following file structure:

-appsettings.json
-Function_function1.cs
-Function_function2.cs
-host.json

在构建和部署项目时,我为wwwroot中的每个功能创建了一个文件夹,每个功能都包含一个function.json文件. appsettings.json文件进入wwwroot/bin文件夹,并且函数无法访问它.

When the project is built and deployed, I end up with a folder for each of the functions in the wwwroot, each of these contains a function.json file. The appsettings.json file goes into the wwwroot/bin folder and the functions are not able to access it.

我认为,如果我将功能项目更改为具有文件夹结构,它将部署appsettings.json,则将其更改为以下内容

I thought that maybe if I changed functions project to have a folder structure it would deploy the appsettings.json, I changed it to the following

-host.json
-Function_function1\
--Function_function1.cs
--appsettings.json
-Function_function2\
--Function_function2.cs
--appsettings.json

这没有达到我期望的结果,在这一点上,我不太确定将应用程序设置复制到wwwroot而不是bin文件夹下的功能文件夹中需要做什么,我们将不胜感激.

This didn't have the result I expected and at this point I am not quite sure what I need to do to get appsettings copied into the function folders under the wwwroot rather than the bin folder, any guidance will be appreciated.

推荐答案

您所引用的SO帖子包含已弃用的信息. appsettings.json不再使用.

The SO post you are referring to contains deprecated information. The appsettings.json isn't used anymore.

对于本地开发,您可以使用local.settings.json文件,但这在Function App中未使用.我刚刚完成测试并验证了此声明.

For local development you can use the local.settings.json file, but this isn't used in the Functions App. I just finished testing this and verified this claim.

您可以在发布函数时使用--publish-local-settings标志,以便在函数应用程序中获取设置.不过,这当然不是您想要的东西.

You can use the --publish-local-settings flag when publishing your function in order to get the settings in your function app. Still, it's not something you want of course.

我本人也在寻找一种不涉及创建ARM模板的解决方案,但是我感觉目前还无法实现. 您当然可以编写自己的PowerShell脚本并以此方式设置应用程序设置,但这甚至更糟.

I myself am also still looking for a solution which doesn't involve creating ARM templates, but I got a feeling this isn't possible at the moment. You can of course write your own PowerShell scripts and set the Application Settings this way, but that's even worse.

可能不是您要找的答案,但这是目前最好的答案.

Probably not really the answer you were looking for, but it's the best there is (at the moment).

这篇关于发布Azure函数并使用appsettings.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆