如何在azuredeploy中使用选项和设置

问题描述 投票:0回答:1

按照文档Working with options and settingsAzure Function v3dotnet core 3.1中的DI一起正常工作。

但是我正在搜索格式选项中的设置参数:在我的azuredeploy.json中的local.settgins.json中有设置

[在Visual Studio中测试要与ARM项目一起部署时,出现此错误。我还没有尝试过,但是我也需要在Azure DevOps管道变量中为不同的环境设置参数。

非常感谢您的帮助。

错误

failed with message '{
  "Code": "BadRequest",
  "Message": "AppSetting with name 'option:setting' is not allowed.",
  "Target": null,
  "Details": [
    {
      "Message": "AppSetting with name 'option:setting' is not allowed."
    },
    {
      "Code": "BadRequest"
    },
    {
      "ErrorEntity": {
        "ExtendedCode": "04072",
        "MessageTemplate": "AppSetting with name '{0}' is not allowed.",
        "Parameters": [
          "option:setting"
        ],
        "Code": "BadRequest",
        "Message": "AppSetting with name 'option:setting' is not allowed."
      }
    }
  ],
  "Innererror": null
}'

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "option:setting": "value"
  }
}

Startup.cs

[assembly: FunctionsStartup(typeof(MyProject.Startup))]
namespace MyProject
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddOptions<MyOption>()
                .Configure<IConfiguration>((settings, configuration) => configuration.GetSection("option").Bind(settings));
        }
    }
}

azuredeploy.parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    ...
    "option": {
      "value": {
        "setting": "value"
      }
    }
  }
}

azuredeploy.json

"resources": [
{
  "apiVersion": "2017-05-10",
  "name": "functionApp",
  "type": "Microsoft.Resources/deployments",
  "properties": {
    "parameters": {
      ...
      "additionalAppSettings": {
        "value": {
          "MSDEPLOY_RENAME_LOCKED_FILES": "1",
          "option:setting": "[parameters('option').setting]"
        }
      }
    },
    "debugSetting": {
      "detailLevel": "requestContent,responseContent"
    }
  }
},
azure azure-devops azure-functions azure-deployment .net-core-3.1
1个回答
0
投票

在文档Configure an App Service app in the Azure portal中找到

只需编辑您的local.settings.json并将char:替换为__GetSection方法可以正常使用。

现在使用azuredeploy.json进行同样的操作。

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "option__setting": "value"
  }
}

azuredeploy.json

"resources": [
{
  "apiVersion": "2017-05-10",
  "name": "functionApp",
  "type": "Microsoft.Resources/deployments",
  "properties": {
    "parameters": {
      ...
      "additionalAppSettings": {
        "value": {
          "MSDEPLOY_RENAME_LOCKED_FILES": "1",
          "option__setting": "[parameters('option').setting]"
        }
      }
    },
    "debugSetting": {
      "detailLevel": "requestContent,responseContent"
    }
  }
},

而且瞧,部署工作完美;)

© www.soinside.com 2019 - 2024. All rights reserved.