katit
katit

Reputation: 17915

How to transform this web.config section?

I have following config for my mail:

<system.net>
    <mailSettings>
      <smtp from="[email protected]" 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="[email protected]" 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?

Upvotes: 19

Views: 11061

Answers (4)

Eugene S.
Eugene S.

Reputation: 3265

For specifiedPickupDirectory element this should work:

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

For System.Diagnostics:

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

Upvotes: 24

Baz1nga
Baz1nga

Reputation: 15579

<system.net>
    <mailSettings>
      <smtp from="[email protected]" 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..

Upvotes: 16

Adam Jones
Adam Jones

Reputation: 721

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.

Upvotes: 1

kobe
kobe

Reputation: 15835

@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.

Upvotes: -4

Related Questions