I want to protect against incorrect case being placed within a parameter in a nant script.
I want to take the value of x and convert it to lower case, I tried using
string::to-lower()
but that did not work hoping someone has come across this and has a simple solution.
<?xml version="1.0" encoding="utf-8"?>
<project name="test" Default="test" value="net-4.0" >
<property name="x" value="default" unless="${property::exists('x')}"/>
<target name="test">
<echo message="${x}" />
</target>
</project>
UPDATE
I tried the suggestion put forward by Yan with the code below this still outputs capitals I will explain further
I have a nant script that has a parameter that can be passed into it, a property checks for the existence of the parameter and if it exists it uses it, if not there is a default value. I want to take the parameter in whatever form it is given and convert it to lower case while still checking for its existence.
<?xml version="1.0" encoding="utf-8"?>
<property overwrite="true" name="x" value="default" unless="${property::exists('x')}"/>
<property overwrite="true" name="x" value="${string::to-lower(x)}" />
<target name="test">
<echo message="${x}" />
</target>
</project>
I believe this to be the way you think I should do it Yan. I have tested this with the following command line arguments.
nant -buildfile:nant.build test -D:x=TEST
This produces the output
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
[property] Read-only property "x" cannot be overwritten.
test:
[echo] TEST
BUILD SUCCEEDED - 0 non-fatal error(s), 1 warning(s)
Total time: 0.1 seconds.
any solution would be much appreciated
When you say parameter, so you mean its name or its value? ie, do you want to ensure x
is lowercase, or test
(I assume the latter)? If I have the following nant script:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" Default="test" value="net-4.0" >
<property overwrite="false" name="x" value="default"/>
<property overwrite="false" name="x_internal" value="${string::to-lower(x)}" />
<target name="test">
<echo message="${x_internal}" />
</target>
</project>
And call it like this:
nant.exe -buildfile:nant.build test -D:x=TESTx
nant.exe -buildfile:nant.build test -D:X=TESTX
I receive the following response:
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
[echo] testx
BUILD SUCCEEDED
Total time: 0 seconds.
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
[echo] default
BUILD SUCCEEDED
Total time: 0 seconds.
Is this what you are after?
UPDATE
I think this is what is tripping you up:
Note: properties set on the command-line are always read-only.