Msbuild - nesting a property inside a property

SilverChips 71 Reputation points
2020-10-20T17:35:17.307+00:00

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$(value2))"></Message>
    </Target>

</Project>

I also tried this

<m>$([System.String]::Concat($(value1), $(value2)))</m>

and the output I get from this

<Message Text = "----Message is: $(m)"></Message>

The output is "HelloWorld" I wanted it to be "This works". Any suggestions ?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
38,604 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 30,336 Reputation points Microsoft Vendor
    2020-10-21T08:00:22.393+00:00

    Hello SilverChips ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    Please refer to this document: CreateProperty task and try following codes:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
     <PropertyGroup>  
     <value1>hello</value1>  
     <value2>world</value2>  
     </PropertyGroup>  
    
     <Target Name="Build">  
     <CreateProperty  
                Value="This work">  
     <Output  
                    TaskParameter="Value"  
                    PropertyName="$(value1)$(value2)" />  
     </CreateProperty>  
     <Message Importance="high" Text="$(helloworld)"></Message>  
     </Target>  
    
    </Project>  
    
    • Update1:

    After testing more, I may misunderstand your requirements. So if you'd like to use value1 and value2 to output value1 value2, then you may need to refer to this document: Task writing and write your own task.

    Sincerely,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.