我有一个通用的 Web 项目,用作多个“子”Web 项目的基础。是否可以在项目之间应用 web.config 转换/合并?假设结构如下所示:
base project
- web.config
child project
- web.config
- transform.config
是否可以进行预构建事件或类似事件,将基础项目 web.config 与子项目 web.config 合并?
最佳答案
您可以编辑到单独的文件 (transform.config) [1] , [2] 和:
Add an
<appsettings>
section and add your data as key/value pairs of the form:<add key="xxx" value="xxxx" />
That's all to create new app.config file with settings in it.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Child1" value="Child1_Value" />
<add key="Child2" value="Child2_Value" />
</appSettings>
</configuration>
连接字符串也是如此 [3] :
<connectionStrings>
<add name="yourConnectionStringName"
connectionString="yourConnectionString"
providerName="System.Data.SqlClient"/>
</connectionStrings>
并使用 configSource
对于父文件:
<connectionStrings configSource="parentWeb.config"/>
关于c# - 在项目之间合并 web.configs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48061900/