Principle to work with targets in MSBuild.
They design MSBuild to call targets using attribute ‘DependsOnTargets’ .
Passing input parameters as properties.
Defining the property using PropertyGroup will NOT work! We need to create a new target, define the property overthere, then call the concerned target. It works that way.
Passing input parameters as batching value from an item list.
We have the tips to pass input as property to a called target, but how can we pass to it a property which is a batched value? -> Use <MSBuild …> to batch the item list & pass the input through its Properties attribute.
See below example.
<Target Name="t"> <ItemGroup> <package Include="1;22;333"/> </ItemGroup> <Message Text="$(MSBuildProjectFile)" /> <MSBuild Projects="$(MSBuildProjectFile)" Targets="transformPackage" Properties="packageName=%(package.Identity)" /> </Target> <Target Name="transformPackage"> <Message Text="2: $(packageName)" /> </Target>
Creating output parameters.
Just create whatever values you need but NOTE that only “not-the-caller” targets can read the new value.