Referencing an MSBuild property using the contents of another property
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?
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...
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.
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
精彩评论