asp.net - 如何将配置转换应用于外部配置文件

标签 asp.net web-config transformation

我在网络上找不到我的问题的示例,并且想知道是否有人知道解决方案。基本上,如果在我们的web.config上,我们指向另一个文件,如下所示:

<configuration>
  <configSections />
  <appSettings file="AppSettings.config">
</configuration>

那么我们如何将转换应用于该外部文件?

基本上,我想创建一个AppSettings.config,AppSettings.Debug.config,AppSettings.Release.config并对其进行转换...甚至可以吗?

提前致谢,

塞尔吉奥

最佳答案

有几种解决方法:

Workaround 1


  • 使用完整值(不具有转换属性)编写AppSettings.Debug.configAppSettings.Release.config
  • 在您的web.config中,使用转换,用适当的文件替换:

  • web.debug.config
    <appSettings file="AppSettings.debug.config" 
                 xdt:Transform="SetAttributes" xdt:Locator="Match(file)"/>
    

    web.release.config
    <appSettings file="AppSettings.release.config" 
                 xdt:Transform="SetAttributes" xdt:Locator="Match(file)"/>
    

    它不太理想,有点违反了转换的目的,但根据个人情况可能比使用SlowCheetah等更合适。

    Workaround 2



    使用TransformXml构建任务在构建过程中按照指定的herehere转换文件

    关于asp.net - 如何将配置转换应用于外部配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8079197/

    相关文章:

    c# - 在asp .net C#中获取返回确认弹出框值

    c# - 如何从 Web.config 读取 system.net/mailSettings/smtp

    iis - 加载配置文件 : Failed to start monitoring changes to '\\share' 时出错

    c++ - 如何正确旋转 GLM 四元数?

    c - 对于多个网格的 FBX 模型,网格未显示在正确的位置

    c# - 不能将重复值插入到唯一索引中(但是...)

    c# - 单击时如何使 Asp.Net 单选框回调?

    javascript - 将 jQuery 引用放在 Masterpage 中有什么好处?

    .net - 将 AssemblyInfo.cs 中的程序集版本放入 Web.config

    javascript - 获取 SVG 元素的当前矩阵变换