如何使用ASP.NET服务器的web.config文件中Azure管道中设置的环境变量? [英] How to use environment variables set in Azure Pipeline in the web.config file of ASP.NET server?
问题描述
我打算在ASP.NET的 web.config
文件中使用Azure管道中的以下env变量:
< connectionStrings><添加名称="ApplicationDbContext" connectionString ="metadata = res://*/Model.csdl | res://*/Model.ssdl | res://*/Model.msl; provider = System.Data.SqlClient; provider connection string =& quot;数据源= tcp:app-$(DeploymentEnvironment).database.windows.net,1433; Initial Catalog = app-db; Persist Security Info = False;用户ID = $(DeploymentDBUserName);密码= $(DeploymentDBPassword);加密=真;应用程序名称= EntityFramework&"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/>
有人可以帮忙吗?
您可以使用扩展任务
您还可以使用
希望上面有帮助!
I intend to use the following env variables from Azure Pipeline in ASP.NET's
web.config
file:<connectionStrings> <add name="ApplicationDbContext" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="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"" 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 />
Could someone help?
解决方案You can use extension task RegEx Find & Replace or RegEx Match & Replace Task to replace REGULAR EXPRESSIONS in the config files with pipeline variables.
First search and install RegEx Find & Replace extension (or
RegEx Match & Replace Task
) in your organization. Then add the task to replace the properties with the variables you defined in the pipeline.You can also use Magic Chunk task to replace the properties in config files with azure pipeline environment variables.
Hope above helps!
这篇关于如何使用ASP.NET服务器的web.config文件中Azure管道中设置的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!