Transformations

Transformations apply to a list of items and enable changing a piece of information for each item in the list into a different format. Consider the following items group, which refers to all text files within a directory:

image

Then imagine you want to send the list of files to the logger. This is accomplished with the following line, to be added into the item group:

<Message Text="@(MyFiles)"/>

The @ Character

The @ character is used for referring to a list of items, differently from $ that is used for referring to a property value.

Now imagine you want to construct the list of items only with the filename and extension without the full path. Transformations enable accomplishing this with a syntax that takes the form of @(itemgroup->'%(itemmetadata)') and where itemmetadata is the piece of information we want to retrieve from the original item and that must be one of the forms recognized by MSBuild, also known as well-known item metadata. So the transformation can be written as follows:

<Message Text="@(MyFiles->'%(FileName)%(Extension)')"/>

FileName and Extension are two of the available well-known item metadata and are information that MSBuild can distinguish within a list of items. The full list item metadata is available at http://msdn.microsoft.com/en-us/library/ms164313.aspx. Suppose you have the following pathnames:

image

When you run MSBuild with the preceding specified transformation, the logger displays the following output:

image

This is possible because of the well-known item metadata information.

Summary

This chapter covered the usage of MSBuild, the build engine for Microsoft platforms that can perform simple and complex compilations from the command line. You first saw how this tool is important because it can work even when Visual Studio is not installed; then you saw the tool in action with some demonstrative command lines. Finally, you got information on advanced features such as tasking, logging, and transformations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.33.157