You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用ARM模板或Bicep配置Azure Functions的.NET8运行时设置

.NET 8 Azure Functions 隔离模式配置(ARM/Bicep)

当你把Azure Functions从.NET 7升级到.NET 8后,由于.NET 8的Functions默认采用隔离工作器模式,需要明确配置FUNCTIONS_WORKER_RUNTIME为dotnet-isolated,同时在ARM/Bicep中对应设置堆栈信息,以下是具体配置方式:

Bicep 配置示例

在你的Function App Bicep文件中,添加环境变量和堆栈运行时配置:

resource functionApp 'Microsoft.Web/sites@2023-01-01' = {
  name: 'your-function-app-name'
  location: resourceGroup().location
  kind: 'functionapp'
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
      appSettings: [
        // 核心环境变量配置
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'dotnet-isolated'
        }
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~4' // .NET 8 对应 Functions Runtime v4
        }
        // 其他必要配置(如存储连接字符串等)
        {
          name: 'AzureWebJobsStorage'
          value: storageAccount.listKeys().keys[0].value
        }
      ]
      // 堆栈运行时设置(Linux环境)
      linuxFxVersion: 'DOTNET-ISOLATED|8.0'
      // Windows环境使用以下配置:
      // windowsFxVersion: 'DOTNET-ISOLATED|8.0'
    }
    enabled: true
  }
}

关键说明:

  • FUNCTIONS_WORKER_RUNTIME必须设为dotnet-isolated,这是隔离模式的核心标识
  • FUNCTIONS_EXTENSION_VERSION指定为~4,.NET 8依赖Functions Runtime v4版本
  • 根据部署环境(Linux/Windows),对应设置linuxFxVersion或windowsFxVersion为DOTNET-ISOLATED|8.0

ARM 模板配置示例

对应ARM模板的配置如下:

{
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2023-01-01",
      "name": "[parameters('functionAppName')]",
      "location": "[resourceGroup().location]",
      "kind": "functionapp",
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "dotnet-isolated"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2022-09-01').keys[0].value, ';EndpointSuffix=', environment().suffixes.storage)]"
            }
          ],
          "linuxFxVersion": "DOTNET-ISOLATED|8.0"
          // Windows环境替换为:"windowsFxVersion": "DOTNET-ISOLATED|8.0"
        },
        "enabled": true
      }
    }
  ]
}

配置完成后,部署模板即可自动完成.NET 8隔离模式的配置,无需手动在Azure门户修改。

内容的提问来源于stack exchange,提问作者Matt Cook

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 13:27:42