MSBuild元属性 - 如何检索属性值,其中属性名称是其他属性的组合?
问题描述:
我希望能写下面的,但在的MSBuild不能:MSBuild元属性 - 如何检索属性值,其中属性名称是其他属性的组合?
<Target Name="SetDynamicPropertyValues">
<PropertyGroup>
<TargetHost>$($(Target-Environment)-Host)</TargetHost>
</PropertyGroup>
</Target>
这在恶性使用property::get-value function容易。对早期问题的回答显示approach using the Condition attribute。
有没有更好的方法来做到这一点?
答
MSBuild处理属性名称一次。要做这种功能,它必须多次调用预处理。我认为使用基于条件的方法会更好。
<PropertyGroup>
<TargetHost Condition="'$(Target-Environment)'=='Env1'">Host_1</TargetHost>
<TargetHost Condition="'$(Target-Environment)'=='Env2'">Host_2</TargetHost>
<TargetHost Condition="'$(TargetHost)'==''">DefaultHost</TargetHost>
</PropertyGroup>