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"] = "jenkins.peterhenell.se:8080"; servers["PROD"] = "www.peterhenell.se:80";// 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="servers.dev" value="localhost:8080" /> <property name="servers.ci" value="jenkins.peterhenell.se:8080" /> <property name="servers.prod" value="www.peterhenell.se:80" /> <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>