The property task documentation shows that the "value" element is a string. So, 
I am guessing anything you put into a property is done with a ToString();

You can run this to prove that out:

<?xml version="1.0" ?>
<project name="TestParse">

                <property name="Item1" value="${int::parse('5')}" />
                <property name="Item2" value="${int::parse('5')}" />
                <echo message="Add ints: ${int::parse('5') + int::parse('5')}"/>
                <echo message="Add props: ${Item1 + Item2}"/>
</project>

The results are:

     [echo] Add ints: 10
     [echo] Add props: 55

BOb


From: Bosch, Andreas [mailto:andreas.bo...@swissray.com]
Sent: Wednesday, October 12, 2011 9:15 AM
To: 'nant-users@lists.sourceforge.net'
Subject: [NAnt-users] Versions in Properties are compared as strings

Hi everyone,

I just figured out why my build script produced a messed up installer: My 
version checks were made as string comparisons rather than real version 
comparisons (without me knowing this). The funny thing is that this worked 
perfectly, but since we changed the version from 0.9.9.0 to 0.9.10.0 it 
suddenly stopped working. New DLLs were not copied although their version had 
been increased. In the end I found out that versions are obviously converted to 
strings (or considered as such) if they are saved in a property and therefore, 
"0.9.9.0" is greater than "0.9.10.0".

The following snippet explains my assumption (source file's version is 
0.9.10.0, and target file's version is 0.9.9.0):

<property
    name="source.file.version"
    
value="${fileversioninfo::get-file-version(fileversioninfo::get-version-info(source.file.absolute))}"/>
<property
    name="target.file.version"
    
value="${fileversioninfo::get-file-version(fileversioninfo::get-version-info(target.file.absolute))}"/>

<echo message="Source file version: ${source.file.version}"/> <!-- 0.9.10.0 -->
<echo message="Target file version: ${target.file.version}"/> <!-- 0.9.9.0 -->

<!-- Property comparison -->
<if test="${source.file.version > target.file.version}">
    <echo message="Property comparison successful!"/>
</if>

<!-- Direct comparison -->
<if 
test="${fileversioninfo::get-file-version(fileversioninfo::get-version-info(source.file.absolute))
 > 
fileversioninfo::get-file-version(fileversioninfo::get-version-info(target.file.absolute))}">
    <echo message="Direct comparison successful!"/>
</if>

<!-- Parsed comparison -->
<if test="${version::parse(source.file.version) > 
version::parse(target.file.version)}">
    <echo message="Parsed comparison successful!"/>
</if>

The result is that the first check ("Property comparison") is not successful, 
while the other two ("Direct" and "Parsed") are successful. Since all checks 
compare the same versions, they should all yield the same results. However, the 
first seems to compare the versions as strings which explains why it worked 
until "0.9.9.0", but does not work with "0.9.10.0".

My question is: Is this the expected behavior? Is it by design? Can someone 
explain this to me? In my eyes, there is no conversion from Version to string 
in my code. I found it very irritating and hard to locate.

Thanks in advance,
Andreas
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to