I am trying to retrieve an MSBuild property ($(Something)) by using the string value "Something" stored in another property. I tried to use MSBuild's Escape/Unescape methods but it still just prints $(Something) and not the property I want:
<Target Name="OutputBuildMacro">
<PropertyGroup>
<PropertyToGet>MSBuildProjectFile</PropertyToGet>
<MacroName>$([MSBuild]::Escape('$'))($(PropertyToGet))</MacroName>
</PropertyGroup>
<Message Text="$([MSBuild]::Unescape('$(MacroName)'))" />
</Target>
Output when I run msbuild TestProject.vcxproj -t:OutputBuildMacro
Project "D:\TestProject\TestProject.vcxproj" on node 1 (OutputBuildMacro target(s)).
OutputBuildMacro:
$(MSBuildProjectFile)
Done Building Project "D:\TestProject\TestProject.vcxproj" (OutputBuildMacro target(s
)).
I also tried to wrap the unescaped value with another pair of $( and ), but that just gives me an error. Is it possible to retrieve msbuild property using a string value rather than literal name written in XML?