简体   繁体   中英

How to transform this web.config section?

I have following config for my mail:

<system.net>
    <mailSettings>
      <smtp from="foo@bar.com" deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:/test"/>
        <network host="localhost" userName="" password=""/>
      </smtp>
    </mailSettings>
  </system.net>

This is my .Release version:

<system.net>
    <mailSettings>
      <smtp from="foo@bar.com" xdt:Transform="RemoveAttributes(deliveryMethod)">
        <network xdt:Transform="Replace" host="192.168.1.9" userName="" password="" />
      </smtp>
    </mailSettings>
  </system.net>

How do I remove

<specifiedPickupDirectory pickupDirectoryLocation="C:/test"/>

so it doesn't show in my .Release at all?

Also, I would like to remove other namespaces like System.Diagnostics completely. What is the syntax for doing so?

For specifiedPickupDirectory element this should work:

<specifiedPickupDirectory xdt:Transform="RemoveAll" /> .

For System.Diagnostics:

<system.diagnostics xdt:Transform="RemoveAll"></system.diagnostics>

<system.net>
    <mailSettings>
      <smtp from="foo@bar.com" xdt:Transform="Replace">
        <network xdt:Transform="Replace" host="192.168.1.9" userName="" password="" />
      </smtp>
    </mailSettings>
  </system.net>

This will replace that entire tag with yours.. hope this is what you are looking for..

the good thing about this is that you dnt end up polluting your transform config with unnecessary remove commands like some of the answers stated here..

consider the case where you have more than one child tags..

Rather than attempting to remove the config from your release version, can you take it from the base version and just add it to the .Debug version? That might be simpler. However if you want to remove it I think you can use <specifiedPickupDirectory xdt:Transform="Remove"/> or something similar.

@katit , you should maintain two different configs for dev and release.

your webconfig should be dynamic and take the configs as below

/qa/yoursettings.config


/release/yoursettings.config

one more sample

<connectionStrings configSource="config\qa\connectionStrings.config"/>

when you go to qa or release , switch your web.config accordingly.

in this way it will be lot cleaner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM