开发者

MSBuild meta-properties - how to retrieve a property value where the property name is a composition of other properties?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜