using cg:applyWhen to insert xml node

Jun 12, 2014 at 7:48 PM

I just saw that there is example of using the cg:applyWhen in the template file. The example suggests it can be used to set values and such. How about using at an XML node level.

Very simple example:

        <cg:applyWhen="$MachineName = 'Prod'">
        <cg:applyWhen="$MachineName != 'Prod'">
            <EnvNote>This is a lab server</EnvNote>

I'm thinking of using this as a way to declare bindings in my web.config files.

For example:

In Lab I want:
<binding name="BasicHttpConfig_Transport" maxReceivedMessageSize="2147483647">
  <security mode="Transport">

However in Prod, that node should not exist.
Jun 23, 2014 at 10:27 AM
The applyWhen is an attribute (rather than an element) and should already do what you want.

Basically, you apply the applyWhen attribute to an element, and this allows you to conditionally include (or not) the element and all its children.

So to take your example, putting the applyWhen attribute directly on the bidning element should include it (and its children) in one case, and exclude it in all others.
<binding cg:applyWhen="$MachineName = 'Prod'" name="BasicHttpConfig_Transport" maxReceivedMessageSize="2147483647">
  <security mode="Transport">
I think one thing that is clear, is that the documentation and examples for ConfigGen need improving. As a user, do you have any specific recommendations? Let me know if you are interested in contributing or editing documentation.

Jun 23, 2014 at 4:49 PM
Thanks for the clarification. As for writing documentation? Does anybody really enjoy doing that? :) I do appreciate your responses here though. Thank you.