首页 > 解决方案 > 用于创建 NET 5 应用服务的 ARM 模板

问题描述

我有一个创建 Azure 应用程序服务的 ARM 模板,它适用于 .NET Core,但我现在想更新模板以部署 NET 5 应用程序服务,我没有任何运气。这是 ARM 架构:https ://docs.microsoft.com/en-us/azure/templates/microsoft.web/sites

这是模板的摘录,我运行它,但是当我查看门户网站时,该站点是使用 .NET Framework 版本的ASPNET 4.8创建的。如何使用 ARM 模板部署 NET 5 站点?

    {
      "name": "[variables('apiAppServiceName')]",
      "type": "Microsoft.Web/sites",
      "apiVersion": "2020-06-01",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[variables('hostingPlanName')]",
        "[variables('databaseName')]",
        "[variables('storageAccountName')]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]": "empty",
        "displayName": "Website",
        "environment": "[parameters('environment')]"
      },
      "properties": {
        "name": "[variables('apiAppServiceName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "httpsOnly": true,
        "clientAffinityEnabled": false,
        "netFrameworkVersion": "net5.0"
      },

标签: azureazure-devopsazure-web-app-serviceazure-resource-manager

解决方案


查看 Azure 生成的模板:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "subscriptionId": {
            "type": "string"
        },
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "hostingPlanName": {
            "type": "string"
        },
        "serverFarmResourceGroup": {
            "type": "string"
        },
        "alwaysOn": {
            "type": "bool"
        },
        "currentStack": {
            "type": "string"
        },
        "phpVersion": {
            "type": "string"
        },
        "netFrameworkVersion": {
            "type": "string"
        }
    },
    "resources": [
        {
            "apiVersion": "2018-11-01",
            "name": "[parameters('name')]",
            "type": "Microsoft.Web/sites",
            "location": "[parameters('location')]",
            "tags": null,
            "dependsOn": [],
            "properties": {
                "name": "[parameters('name')]",
                "siteConfig": {
                    "appSettings": [],
                    "metadata": [
                        {
                            "name": "CURRENT_STACK",
                            "value": "[parameters('currentStack')]"
                        }
                    ],
                    "phpVersion": "[parameters('phpVersion')]",
                    "netFrameworkVersion": "[parameters('netFrameworkVersion')]",
                    "alwaysOn": "[parameters('alwaysOn')]"
                },
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "clientAffinityEnabled": true
            }
        }
    ]
}

和参数

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "subscriptionId": {
            "value": "someId"
        },
        "name": {
            "value": "testdotnet5"
        },
        "location": {
            "value": "Central US"
        },
        "hostingPlanName": {
            "value": "ServicePlan43e7dac6-ad18"
        },
        "serverFarmResourceGroup": {
            "value": "recruiterly"
        },
        "alwaysOn": {
            "value": false
        },
        "currentStack": {
            "value": "dotnet"
        },
        "phpVersion": {
            "value": "OFF"
        },
        "netFrameworkVersion": {
            "value": "v5.0"
        }
    }
}

你应该使用

        "netFrameworkVersion": {
            "value": "v5.0"
        }

推荐阅读