c# - Azure Function - 在 Visual Studio 2017 中为不同环境添加不同的设置文件

标签 c# visual-studio azure azure-functions

我使用 Visual Studio 2017 创建了一个 Azure 函数,它使用 local.settings.json 文件来存储数据库连接字符串,该字符串非常适合我的测试环境。

现在我需要为临时环境添加数据库连接字符串。如何创建单独的 staging.settings.json 文件并将其关联到 Visual Studio 中的暂存版本,以便它将采用 staging.settings.json 文件的设置在分阶段部署期间?

我创建了一个 staging.settings.json 并从 local.settings.json 复制了设置文件:

{
  "IsEncrypted": false,
  "Values": {
    "sql_conn": "Server=tcp:SERVER,1433;Initial Catalog=DBNAME;Persist Security Info=False;User ID=;Password=;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
   }
}

最佳答案

暂存功能托管在 Azure 中,local.settings.json 文件不会上传到 Azure。仅适用于本地开发。

在 Azure 门户中,您的 pro Function 和 staging Function 有不同的应用程序设置页面,因此您可以直接设置值。

enter image description here

当我们用 VS 发布 Functions 时,有一个 friendly dialog更新应用程序设置。您还可以在那里配置连接字符串。远程设置将上传到 Azure。

enter image description here

enter image description here

关于c# - Azure Function - 在 Visual Studio 2017 中为不同环境添加不同的设置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55387221/

相关文章:

Azure API管理: Set different backend url for different endpoints

azure - 自动向 Visual Studio Online 中的用户授予权限

azure - Microsoft/Azure OAuth 失败,我的组织缺少服务主体

c# - 如果 "Utilities"类是邪恶的,我应该把我的通用代码放在哪里?

c# - 使用 Azure 管理 C# API 创建资源组

visual-studio - 如何调试VS2010安装项目?

c# - Method : String. 长度的计量单位

c# - Asp.net Core Web API在 Controller 级别之外基于资源的授权

java - 试图将 api 身份验证从 iOS 应用程序复制到 java 中,不要用户理解代码

c# - Visual Studio SDK - 处理文件添加、删除和重命名事件