c# - 在项目之间合并 web.configs

标签 c# asp.net web-config web.config-transform

我有一个通用的 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/

相关文章:

asp.net - 如何在我的 web.config 中设置默认的 text/html 内容类型?

c# - 系统.安全.SecurityException : Request for principal permission failed

c# - 如何使用 Blob 存储中的 Azure 函数和 C# 以及将 JSON 数据作为列存储在 Azure 表存储中从 JSON 文件获取数据

c# - 带参数运行exe不起作用

c# - 如何检查 Observable 集合中已经存在的值

javascript - ASP NET MVC 5 从网站中删除文件

javascript - log4javascript web.config

c# - 尝试在 .NET Core 3.0 中植入角色时,获取任务被取消错误

c# - 如果在 FormView 中,在哪里设置 ListBox Selected 索引?

asp.net - ASP.NET AJAX CascadingDropDown 的 jQuery 更改值