Azure Functions .NET 3版本终止支持后,创建时遇运行时找不到异常求解决
解决方案
指定明确的.NET Runtime版本
Azure Functions v3对应.NET Core 3.1,由于该版本已终止支持,默认--runtime dotnet会指向当前受支持的.NET版本(如6.0/7.0),导致运行时找不到。修改原命令,添加--runtime-version 3.1参数即可:az functionapp create --name ${{FunctionName }} --os-type Windows --resource-group ${{resourceGroup }} --storage-account ${{ appTierStorageAccountName }} --runtime dotnet --runtime-version 3.1 --functions-version 3 --plan ${{ appServicePlan }} --app-insights ${{ appInsightsName }} --app-insights-key $(AppInsightsInstrumentationKey)使用ARM模板创建(更可靠)
如果CLI命令仍无法执行,可改用ARM模板精准配置运行时参数。在模板的siteConfig节点中指定Windows运行时为DOTNET|3.1,同时设置FUNCTIONS_EXTENSION_VERSION为~3,核心配置片段如下:{ "type": "Microsoft.Web/sites", "apiVersion": "2022-03-01", "name": "[variables('functionAppName')]", "properties": { "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]", "siteConfig": { "windowsFxVersion": "DOTNET|3.1", "appSettings": [ { "name": "FUNCTIONS_EXTENSION_VERSION", "value": "~3" }, { "name": "APPINSIGHTS_INSTRUMENTATIONKEY", "value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName'))).InstrumentationKey]" }, { "name": "AzureWebJobsStorage", "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2021-04-01').keys[0].value, ';EndpointSuffix=', environment().suffixes.storage)]" } ] } } }之后通过Azure DevOps的ARM模板部署任务执行应用创建。
降级Azure CLI版本(备选方案)
新版本Azure CLI已移除对.NET 3.1运行时的默认支持,可在DevOps代理上将Azure CLI降级到2.40.0及以下版本(该版本仍保留对.NET 3.1的支持),再执行原命令。
内容的提问来源于stack exchange,提问作者Heshan
相关产品推荐
相关产品推荐

