问题描述
我正在Visual Studio Team Services中进行Azure应用服务部署(ASP.NET Core 2.0 Web Api),并且想要替换appsettings.json中的某些值,因此我阅读 https://docs.microsoft.com/zh-CN/vsts/build-release/tasks/transforms-variable-substitution#jsonvarsubs ,但他们讨论的是通过用句点(.)将名称替换为嵌套级别的文件中的值.
I'm doing an Azure App Service Deploy (ASP.NET Core 2.0 Web Api) in Visual Studio Team Services and want to replace some values in the appsettings.json so I read https://docs.microsoft.com/en-us/vsts/build-release/tasks/transforms-variable-substitution#jsonvarsubs, but they talk about substituting values in nested levels of the file, by concatenate the names with a period (.).
问题是您不能在Azure Key Vault中使用句点(.).
Problem is that you can't use periods (.) in an Azure Key Vault.
有人知道如何使用Azure Key Vault中的Secrets在appsettings.json文件中用嵌套级别替换变量吗?
Does anyone know how to substitute variables with nested levels in an appsettings.json file using Secrets from the Azure Key Vault?
推荐答案
我最终在Azure Key Vault中使用"ConnectionStrings--Database"作为密钥.
I ended up using 'ConnectionStrings--Database' as Secret key in Azure Key Vault.
然后在VSTS中添加变量组"( https://docs.microsoft.com/en-us/vsts/build-release/concepts/library/variable-groups )链接到Azure Key Vault.
Then adding a 'Variable Group' in VSTS (https://docs.microsoft.com/en-us/vsts/build-release/concepts/library/variable-groups) linking to the Azure Key Vault.
并添加一个名为"ConnectionStrings.Database"的过程变量",其值为"$(ConnectionStrings--Database)".
And add a 'Process Variable' called ConnectionStrings.Database with a value of '$(ConnectionStrings--Database).
这样,它将流程变量"的值替换为Azure Key Vault中的值,并使用流程变量"的名称替换appsettings.json中的内容.
That way it replaces the value of your 'Process Variable' with the value from the Azure Key Vault and it uses the name of the 'Process Variable' to replace in the appsettings.json.
这篇关于VSTS JSON变量替换为Azure Key Vault中的机密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!