Nant - Property as a dictionary

Post date: Feb 5, 2016 8:15:31 AM

There is no built in Dictionary-type property in Nant. There are some third party libraries that provide such functionality but you can also do it with standard Nant.

The idea is that you want to access the value of some property based on the value of another property.

In C#:

var servers = new Dictionary<string,string>(); servers["DEV"] = "localhost:8080"; servers["CI"] = ""; servers["PROD"] = "";// We can now dynamically choose the url to a server based on a stringvar currentEnvironment = ReadFromConfiguration(ConfigKeys.CurrentEnvironment);var targetServer = servers[currentEnvironment];

In Nant this would look like this:

<property name="" value="localhost:8080" /> <property name="" value="" /> <property name="" value="" /> <target name="default"> <property name="current.environment" value="dev" /> <property name="target.server" value="${property::get-value('servers.' + current.environment)}" /> <echo message="${target.server}" /> </target>