I'd like to be able to write the below, but I can't in MSBuild:
<Target Name="SetDynamicPropertyValues">
<PropertyGroup>
<TargetHost>$($(Target-Environment)-Host)</TargetHost>开发者_高级运维
</PropertyGroup>
</Target>
This is easily done in NAnt using the property::get-value function. The answer to an earlier question shows an approach using the Condition attribute.
Is there a nicer way to do this?
MSBuild processes property names once. To do that kind of feature it must call the preprocessing several times. I think it would be better to use a Condition-based approach.
<PropertyGroup>
<TargetHost Condition="'$(Target-Environment)'=='Env1'">Host_1</TargetHost>
<TargetHost Condition="'$(Target-Environment)'=='Env2'">Host_2</TargetHost>
<TargetHost Condition="'$(TargetHost)'==''">DefaultHost</TargetHost>
</PropertyGroup>
精彩评论