tags:

views:

35

answers:

3

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?

+1  A: 

I don't believe that is possible. However, you could achieve a similar effect with ItemGroups:

<PropertyGroup>
    <SelectVariable>Test</SelectVariable>
</PropertyGroup>

<ItemGroup>
    <Variable Include="1">
        <Select>Test</Select>
    </Variable>
    <Variable Include="2">
        <Select>Full</Select>
    </Variable>
</ItemGroup>

<Message Text="@(Variable)"
         Condition=" '%(Select)' == '$(SelectVariable)' " />

It's a little clunky tho...

Peter McEvoy
+1  A: 

You could use the <Choose> task to achieve something similar, but (as Peter said) that's likely to be some distance from your desire to have something short and pithy.

Perhaps psake is the answer - it has no such arbitrary and puny limits when nesting expressions and parentheses :P

Ruben Bartelink
I think the Choose task is the answer here.
Benjamin Baumann
+1  A: 

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"&gt;
  <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 image below. alt text

Sayed Ibrahim Hashimi
Doh! Slaps head. Shoulda seen that one!
Peter McEvoy
I don't think that's what vicjugador wants. I think he wants some kind of reflexion. In your example he wants to output the value of TestVariable (1) and not the name (TestVariable). And I don't think it's possible because it would need several passes to interpretate the file...
Benjamin Baumann
Benjamin is correct .. the output that I want is the contents of TestVariable (1) .. and not the name of TestVariable.
vicjugador