[MSBuild] Input/Output parameters when calling a Target

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">
   <package Include="1;22;333"/>
 <Message Text="$(MSBuildProjectFile)" />
 <MSBuild Projects="$(MSBuildProjectFile)" Targets="transformPackage" Properties="packageName=%(package.Identity)" />

<Target Name="transformPackage">
 <Message Text="2: $(packageName)" />

Creating output parameters.

Just create whatever values you need but NOTE that only “not-the-caller” targets can read the new value.

Passing input parameters as an item list.


2 responses to this post.

  1. Posted by Vitaliy on November 22, 2011 at 10:38 PM

    Hallo! I invoke two targets this way and one target uses values created in other target. And second target for each value of property recieves the values created in the first target for the same input property. It’s exactly what i need but I can’t find the reference for this ability and can’t use it in serious project. Can you explain this?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: