$(TargetPath) not evalutated on loading macro?
To resolve this issue you should import your custom.props
file after importing file Microsoft.Cpp.targets
:
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="Custom.props" />
That because the value of Macros for Build Commands and Properties set by the file Microsoft.Cpp.Current.targets
:
<Target Name="SetUserMacroEnvironmentVariables"
Condition="'@(BuildMacro)' != '' and '$(DesignTimeBuild)' != 'true'">
<SetEnv Condition="'%(BuildMacro.EnvironmentVariable)' == 'true'"
Name ="@(BuildMacro)"
Value ="%(BuildMacro.Value)"
Prefix ="false">
<Output TaskParameter="OutputEnvironmentVariable" PropertyName="%(BuildMacro.Identity)"/>
</SetEnv>
</Target>
And the file Microsoft.Cpp.Current.targets
is imported by the file Microsoft.Cpp.targets
:
<Import Condition="'$(_Redirect)' != 'true'" Project="$(VCTargetsPath)\Microsoft.Cpp.Current.targets" />
So if you call the some macro in your custom file before importing the file Microsoft.Cpp.targets
, MSBuild could not get the value of macro.
You can get those .targets
files at following path:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets
To verify the custom value of VST2_32_COMMAND_ARGS
, I add a simple target to output that value. So you project file should be like:
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<Import Project="Custom.props" />
<Target Name="TestByCustom" AfterTargets="Build">
<Message Text="$(VST2_32_COMMAND_ARGS)"></Message>
</Target>
After build completed, we could get the value of $(TargetPath)
:

My custom.props file:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VST2_32_COMMAND_ARGS>"$(TargetPath)" /noload /nosave /noexc /noft</VST2_32_COMMAND_ARGS>
</PropertyGroup>
</Project>
Hope this helps.