Msbuild - nesting a property inside a property

236 views Asked by At

I currently have something like this I would like to display the output of the property helloworld by joining the value of properties value1 and value2. I tried doing $(value1$(value2)) but that doesnt work any suggestions ?

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <value1>hello</value1>
        <value2>world</value2>
        <helloworld>This works</helloworld>
    </PropertyGroup>
    
    <Target Name="Build">
    <Message Text = "----Message is: $(value1)"></Message>
    <Message Text = "----Message is: $(value1$(value2))"></Message> --->Error :Should display `This works`      
    </Target>
    
</Project>
1

There are 1 answers

0
Jonathan Dodds On

Properties don't 'nest'. Actually what you are trying to do, is dynamically generate a property name and then lookup the value for that property name. That is not supported in MSBuild. You can do this in some languages (for example if the language has an eval() function), but not MSBuild.

Property functions can be nested and properties can be used for parameters to property functions.

e.g.

    <PropertyGroup>
        <File>test.proj</File>
        <Archive>$([MSBuild]::BitwiseAnd(32, $([System.IO.File]::GetAttributes($(File)))))</Archive>
    </PropertyGroup>

The value of the $(File) property is passed to GetAttributes().

The return value of GetAttributes() is passed to BitwiseAnd().