web.config转换-从connectionstring部分删除注释 [英] web.config transform - delete comments from connectionstring section
问题描述
我将几个不同的连接字符串存储在我的web.config中,以进行开发和测试.除了一个以外的所有内容都已被注释掉,因此我可以根据需要更改信息.
I store several different connection strings in my web.config for development and testing. All but one is commented out so I can change info as needed.
发布时,我想用以下内容替换connectionStrings节点中的所有内容(包括注释):
When I publish, I would like to replace everything (including comments) in the connectionStrings node with this:
<add name="myDb" connectionString="Data Source={SERVER};Initial Catalog=ManEx;User Id={USER};Password={PASSWORD};" providerName="System.Data.SqlClient" />
<!--<add name="myDb" connectionString="Data Source={SERVER};Initial Catalog=ManEx;Integrated Security=True" providerName="System.Data.SqlClient" />-->
我知道该如何更改活动字符串:
I know how to change the active string with this:
<add name="myDb"
connectionString="Data Source={SERVER};Initial Catalog=ManEx;User Id={USER};Password={PASSWORD};"
providerName="System.Data.SqlClient"
xdt:Transform="Add"
xdt:Locator="Match(name)"/>
但是我不知道如何清除我不想要的评论并添加我想要的评论.
But I don't know how to clear out the comments I don't want and add the comment I do want.
有什么想法吗?
推荐答案
而不是转换字符串,或使用删除"和插入"来清洁该部分,请尝试使用替换".
Instead of transforming the string, or using "Remove" and "Insert" clean the section try using "Replace".
例如:
<connectionStrings xdt:Transform="Replace">
<add name="myDb"
connectionString="Data Source={SERVER};Initial Catalog=ManEx;User Id={USER};Password={PASSWORD};"
providerName="System.Data.SqlClient" />
</connectionStrings>
即使这意味着您要添加新评论,也可以根据需要完全配置此部分.
You can configure this section exactly how you want it, even if that means you add new comments.
这篇关于web.config转换-从connectionstring部分删除注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!