gpt4 book ai didi

c# - 如何在ASP.NET服务器的web.config文件中使用Azure Pipeline中设置的环境变量?

转载 作者:行者123 更新时间:2023-12-03 23:49:17 26 4
gpt4 key购买 nike

我打算在 ASP.NET 的 web.config 中使用来自 Azure Pipeline 的以下环境变量文件:

<connectionStrings>
<add name="ApplicationDbContext" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:app-$(DeploymentEnvironment).database.windows.net,1433;Initial Catalog=app-db;Persist Security Info=False;User ID=$(DeploymentDBUserName);Password=$(DeploymentDBPassword);Encrypt=True;Application Name=EntityFramework&quot;" providerName="System.Data.EntityClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
<add name="ServiceBus" connectionString="Endpoint=sb://app-$(DeploymentEnvironment)-bus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=$(ServiceBusAccessKey)" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
<add name="Cache" connectionString="app-$(DeploymentEnvironment)-cache.redis.cache.windows.net:6380,password=$(CachePassword),ssl=True,abortConnect=False,allowAdmin=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
<connectionStrings />

有人可以帮忙吗?

最佳答案

您可以在 Azure Pipelines 中使用名为“替换 token ”的工具

例如您有环境变量:var_1 = 某个值

然后你的标记化配置文件将是这样的:

<connectionStrings>
<add name="ApplicationDbContext" connectionString="con-#{var_1}#" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)"/>
<connectionStrings />

那么转换后你会得到:

<connectionStrings>
<add name="ApplicationDbContext" connectionString="con-some_value" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)"/>
<connectionStrings />

关于c# - 如何在ASP.NET服务器的web.config文件中使用Azure Pipeline中设置的环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59962204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com