MSBuild meta-properties - how to get the value of a property when the property name is part of other properties?

I would like to be able to write below, but I cannot in MSBuild:

<Target Name="SetDynamicPropertyValues"> 
   <PropertyGroup>
      <TargetHost>$($(Target-Environment)-Host)</TargetHost>
   </PropertyGroup>
</Target>

This is easy to do in NAnt using the property :: get-value function . The answer to the previous question shows an approach using the Condition attribute .

Is there a better way to do this?

+3
source share
1 answer

MSBuild processes property names once. To make such a function, it must call preprocessing several times. I think it would be better to use a conditional 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
source

All Articles