Azure Function builder.GetContext().EnvironmentName 始终为“开发”

chi*_*Dev 5 .net-core azure-functions azure-functions-runtime

参考官方文档

如果在 Azure 中运行时不存在此应用程序设置,则假定环境为生产环境。

即使在覆盖AZURE_FUNCTIONS_ENVIRONMENT并ASPNETCORE_ENVIRONMENT进入生产之后,我仍然在 Azure 中进行开发。

我的 Azure Function 是在 Windows 环境上运行的无服务器消费计划,运行时版本 ~3。

Ser*_*kyi 2

打开启动设置 Properties/launchSettings.json 该文件包含类似于以下的 json :

  "profiles": {
    "YourProject": {
      "commandName": "Project",
      "environmentVariables": {
        "AZURE_FUNCTIONS_ENVIRONMENT": "Development"
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

您可以像示例中那样指定环境变量。