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

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

问题描述

我有一个 Azure Functions 项目,我正在使用 Visual Studio 2017 15.3 preview 7 用 C# 编写该项目.函数项目包含两个单独的函数,这两个函数都是计时器触发的.我在 appsettings.json 文件中指定了许多 appsettings,该文件设置为 Copy to the output directory on build.

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 Functions - using 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

这没有达到我预期的结果,此时我不太确定我需要做什么才能将 appsettings 复制到 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 文件,但在 Functions 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天全站免登陆