How do I create a property in msbuild so that I can use it in a CallTarget directive?
Essentially I am trying to call a target 'subroutine' where the properties act as parameters.
I tried making a toy csproj file which attempts to create a property, and then calls a target which echos it. It echos null.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Test">
<CreateProperty Value="AAA">
<Output TaskParameter="Value" PropertyName="Foo" />
</CreateProperty>
<CallTarget Targets="Test2" />
</Target>
<Target Name="Test2">
<Message Text="Target Test2: Foo=$(Foo)" />
</Target>
</Project>
Running msbuild TestProj.csproj /t:Test
outputs:
Test:
Target Test: Foo=AAA
Test2:
Target Test2: Foo=
I guess the problem is I'm thinking about msbuild in an imperative fashion (which is apparently a common mistake), so I'm hoping someone can correct what appears to be a very fundamental misunderstanding in how msbuild works.