c# - 使用 Jetbrains Rider 和 Azure Toolkit 以及本地设置部署 Azure Function

标签 c# azure deployment azure-functions rider

我正在 Mac 上使用 Jetbrains Rider 来开发一些 Azure Functions (.NET 6/C#)。我使用 Azure Toolkit 将它们部署到 Azure(在这种情况下,CI/CD 流程将被过度设计)。基本部署对我来说工作得很好。

但是,在我公司笔记本电脑上的 Visual Studio Professional/Enterprise(使用 Windows)中,我可以选择使用选定的本地设置子集来部署 Azure Functions。

对于任何对此选项感兴趣的人,这里有描述(屏幕截图不是 VS 2022 的最新版本,但您会找到它):https://learn.microsoft.com/en-us/answers/questions/513945/how-can-i-make-azure-functions-use-settings-in-loc

Jetbrains Rider 中有内置选项吗?或者我必须使用 Azure CLI 吗?

enter image description here

最佳答案

By default local.settings.json is not deployed in Azure Functions as it is used for local development and also its part of gitignore file where it is not included during runtime, Refer this SO thread answer by Chris B and below:-

gitignorefile:-

enter image description here

遗憾的是,在使用 Jet-Brains Rider 发布 Azure Functions 时,无法像在 Visual Studio 代码中那样在发布时编辑和配置应用程序设置,但您可以使用 Azure 工具包 > Azure 添加它资源管理器和功能应用程序请参阅以下内容:-

我在 JetBrains IDE 中创建了一个 Azure Function 应用程序,并将其发布到我的 Azure Function 应用程序中,如下所示:-

enter image description here

在函数中添加了 HTTP 触发器,如下所示:-

enter image description here

enter image description here

我在本地运行该函数并成功触发:-

enter image description here

将此函数发布到 Azure 中的函数应用程序时,没有编辑应用程序设置的选项,请参阅以下内容:-

enter image description here

enter image description here

我单击“运行”,函数已成功部署在函数应用程序中,请参阅以下内容:-

enter image description here

您可以在发布触发器之前或发布触发器之后在 Function 应用中添加应用设置,因为应用设置是应用于其中所有触发器的函数应用级别设置,请按照以下步骤操作:-

转到 JetBrains Rider 中的 Azure Explorer > 选择您的 Function App > 右键单击​​ > 显示属性,如下所示:-

enter image description here

将加载功能应用程序发布配置文件和应用程序设置页面 > 单击添加 '+'应用程序设置右侧部分的按钮并添加您的设置,如下所示:-

enter image description here

点击如下所示的“保存”以保存您的应用设置:-

enter image description here

在功能应用程序中成功添加应用程序设置,请参阅以下内容:-

enter image description here

门户中反射(reflect)的应用设置:-

enter image description here

你是对的,作为一种解决方法,你可以通过 Azure CLI 直接添加 Function App 设置,如下所示:-

命令:-

我从这个 MS Document 引用了以下命令.

az functionapp config appsettings set --name siliconfunc45 --resource-group siliconrg1 --settings 'SCM_DO_BUILD_DURING_CONFIGURATION = true'

enter image description here

enter image description here

门户:-

enter image description here

关于c# - 使用 Jetbrains Rider 和 Azure Toolkit 以及本地设置部署 Azure Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76243821/

相关文章:

c# - 根据特定条件将列表分为两个列表

azure - 与另一个 Azure AD B2C 租户联合时映射声明

c# - 在 C# 中循环字典

c# - Windows 窗体的基本布局

sql-server - 从 Visual Studio 将 DB 与 Azure MFA 连接以将项目解决方案与 Azure DB 进行比较?

azure - 在自主位置之间路由流量的最佳 Azure 产品是什么

c++ - 升级到 .NET 4.5 后部署项目中对 .NET 的不必要依赖

java - JBoss 部署错误 : Caused by: java. lang.RuntimeException : . application.xml 中列出的 war 模块在 .ear 中不存在

ruby-on-rails - 在 Elastic Beanstalk 上设置 delay_job 时如何修复 'require' 错误

c# - 如何直接从 .net 应用程序创建 Excel 工作表数据?