Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 999
katit Avatar asked Aug 23 '11 19:08

katit


People also ask

How do I create a Web config transform?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

How do I rename a Web config transform?

If you are using the extension Configuration Transform go to Build > Configuration Manager and find the Configuration dropdown for the project of which you want to change the app config. You can then select the edit and rename the build configurations for that project.

What is Xdt transform in Web config?

A transform file is an XML file that specifies how the Web. config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix.


2 Answers

For specifiedPickupDirectory element this should work:

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

For System.Diagnostics:

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

like image 51
Eugene S. Avatar answered Sep 30 '22 18:09

Eugene S.


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

like image 27
Baz1nga Avatar answered Sep 30 '22 19:09

Baz1nga