Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing an MSBuild property using the contents of another property

Tags:

msbuild

I want to be able to reference an MSBuild (3) property using the contents of another property. For example:

<PropertyGroup>
    <SelectVariable>Test</SelectVariable>
    <TestVariable>1</TestVariable>
    <FullVariable>2</FullVariable>
</PropertyGroup>

<Message Text="Value $($(SelectVariable)Variable)"/>

In this scenario, I want the contents of TestVariable outputted (1). Is this possible?

like image 553
vicsz Avatar asked Dec 30 '25 12:12

vicsz


1 Answers

Sure this is possible. Just do:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <SelectVariable>Test</SelectVariable>
    <TestVariable>1</TestVariable>
    <FullVariable>2</FullVariable>
  </PropertyGroup>

  <Target Name="Demo01">
    <PropertyGroup>
      <Value>$(SelectVariable)Variable</Value>
    </PropertyGroup>
    <Message Text="Value $(Value)"/>
  </Target>

</Project>

The result is shown in the image below.

Alt text

like image 124
Sayed Ibrahim Hashimi Avatar answered Jan 01 '26 21:01

Sayed Ibrahim Hashimi