This project is read-only.

Environment Property value True or False

Aug 26, 2011 at 12:08 AM

I need to populate section of the xml based on True or False Property value.

 

Could you please tell me how can i use the property in my input xml so that it will populate section based on Environment value.?

 

 <!-- #ifdef _xml_preprocess -->
    <!-- IF ${TrueorFalse} -->
        populatesection
  <!-- endif -->
<!-- #else --> <!-- #endif -->

 

Aug 26, 2011 at 4:29 PM

First: You don't need to have the "#ifdef _xml_preprocess" there.  I don't think it handles nested preprocessor commands, or at least I haven't been able to make it handle them, and I haven't read the code to figure out if it is supposed to or not.

Now you say you want to set something based on an Environment value.  Are you talking about a "real" Environment value such as PATH or are you talking about an environment value within XmlPreProcess?

The basics answer is that the #if preprocessor executes C# code to determine a true or false value.  It also has a couple of helper functions called GetProperty("PropertyName") and defined("PropertyName") that you can use.  GetProperty is used to get the value of the given property.  defined is used to check to see if the given property is defined.  See the "What's New" section referring to the #if for some more information.

For example:

If I have a property named "Foobar" defined that has the values true or false for different environments, then I can do the following within my input xml:

<!-- #if Convert.ToBoolean(GetProperty("Foobar")) -->
<!--
    populatesection if Foobar is true
-->
<!-- #else -->
<!-- #endif -->

<!-- #if ! Convert.ToBoolean(GetProperty("Foobar")) -->
<!--
    populatesection if Foobar is false
-->
<!-- #else -->
<!-- #endif -->

Notice also that you can use GetProperty to compare the actual value, such as if Foobar were a regular string value then you could do GetProperty("Foobar") == "MyString".

Does that help?

Nov 23, 2011 at 12:52 AM

Used this today.  Thanks, AMcMillan!

Apr 27, 2012 at 8:28 AM
<!-- #if ! Convert.ToBoolean(GetProperty("Foobar")) -->
<!--
    populatesection if Foobar is false
-->

<!-- #else -->
<!-- #endif -->

Notice also that you can use GetProperty to compare the actual value, such as if Foobar were a regular string value then you could do GetProperty("Foobar") == "MyString".

Does that help?

This last comment really helped me !

Couldn't find much info on how to use a regular if construction. But with this comment and the source code figured it out.

<!-- #if GetProperty("_machine_name") == "MyServerName"  -->

 

<!-- <entry machine_name="${_machine_name}" /> -->

 

 

 

 

<!-- #endif -->

 

 

 

Thanks