开发者

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

开发者 https://www.devze.com 2023-02-17 10:45 出处:网络
I\'d like to be able to write the below, but I can\'t in MSBuild: <Target Name=\"SetDynamicPropertyValues\">

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

精彩评论

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

关注公众号