2010-10-21 67 views
2

我希望能够使用另一个属性的内容引用msbuild(3)属性。例如:使用另一个属性的内容引用msbuild属性

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

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

在这种情况下,我想输出TestVariable的内容(1)。这可能吗?

回答

2

我不相信这是可能的。但是,你可以实现与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)' " /> 

这是一个有点笨拙寿...

1

您可以使用<Choose> task来实现类似的东西,但(如彼得说),这很可能是与你渴望拥有短而精悍的东西有一些距离。

也许psake就是答案 - 嵌套表达式和括号,当它没有这样的武断和微不足道的限制:P

+0

我觉得选择任务就是这里的答案。 – 2010-10-25 16:03:02

2

相信这是可能只是做:

<?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> 

结果在下面的图片所示。 alt text

+0

Doh! Sla头。应该看到一个! – 2010-10-23 10:38:24

+0

我不认为这就是vicjugador想要的。我想他想要某种反思。在你的例子中,他想输出TestVariable(1)的值而不是名称(TestVariable)。我不认为这是可能的,因为它需要几次通过解释文件... – 2010-10-25 16:01:49

+0

本杰明是正确的..我想要的输出是TestVariable(1)..的内容,而不是TestVariable的名称。 – vicsz 2010-10-25 18:25:15