• .net随笔——Web开发config替换到正式config appSettings


    前言(废话)

      查了一些资料,总体来说呢,就是坑,而且顺带吐槽下百度,一个内容被copy那么多遍还排在最前面。同一个内容我点了那么多次,淦。

    正题:

      实现目的:开发的时候使用system.debug.config这个配置文件

           发布的时候使用system.Release.config这个配置文件

    我为啥这么干,因为公众号的临时token我存在这配置文件里面。每次发布都得清楚,贼鸡儿麻烦

     所以我用到了webconfig转换

    --------------贴使用代码begin----------------------------------------

    这是web.config里面的配置
    <configuration>
      <appSettings configSource="Configsystem.Debug.config" />
    </configuration>
    
    注意:这里是web.release.config里面的配置
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings configSource="Configsystem.Release.config" xdt:Transform="Replace" xdt:Locator="XPath(/configuration/appSettings)" />
      <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
      </system.web>
    </configuration>
    

    --------------贴使用代码end----------------------------------------

    就这么完事,接下来是解释。

    正如网上说的,发布的时候会自动替换。

    那么是怎么样的替换法:

      第一:关键属性xdt:Transform="Replace"。。。这个xdt:Transform很多用法主要作用就是操作,

          可以替换Replace、

          可以添加Insert、

          或者InsertBefore和InsertAfter、

          以及Remove与RemoveAll、

          RemoveAttributes(debug,batch)这个也不知道咋用的玩意、

          SetAttributes(batch)

          SetAttributes(viewStateEncryptionMode)

      第二:筛选xdt:Locator="XPath(/configuration/appSettings)"  这个条件的语法是:xdt:Locator="XPath(XPath Expression)" 。或者xdt:Locator="Condition(XPath Expression)" 进行某个属性的操作

        是XPathExpression表达式,这个可以参照这位老哥的 https://www.cnblogs.com/james-dong/articles/438825.html

  • 相关阅读:
    Direct UI 思想阐述(好多相关文章)
    GetSystemTimeAsFileTime讲解(从1601年1月1日到目前经过的纳秒)
    WPF的消息机制
    CEdit 样式与消息 解析
    vcredist_x86.exe 静默安装方法
    iOS 开发问题集锦(一)
    EM算法详解
    BCP导入导出MsSql
    为什么不能在子类或外部发布C#事件
    HTML5 拖放及排序的简单实现
  • 原文地址:https://www.cnblogs.com/bklsj/p/13750098.html
Copyright © 2020-2023  润新知