Reading msbuild syntax

127 views Asked by At

I've run across msbuild syntax that I don't understand. The following snippet is from another question about making a custom msbuild task

<GenerateDesignerDC
  InputFiles="@(dbml)"
  OutputFiles="@(dbml->'$(IntermediateOutputPath)%(FileName).designer.cs')">
    ...

What does @(dbml->'$(IntermediateOutputPath)%(FileName).designer.cs') mean? The @ sign usually references the files in an ItemGroup; what does the -> arrow inside an @(...) mean?

What is this little language (with the @s, $s, %s, ->, etc.) used for substitutions into the attributes of build tasks called?

2

There are 2 answers

0
Cirdec On BEST ANSWER

This specific syntax is called a transform.

A transform is a one-to-one conversion of one item list to another. In addition to enabling a project to convert item lists, a transform enables a target to identify a direct mapping between its inputs and outputs.

The syntax isn't explicitly documented. The part before the -> is an item list like that which would normally be referenced by @. In the example @(dbml->...) it is transforming the dbml item list. The part after the -> is an expression for the new file name. It can refer to any item metadata with a % symbol. In the example it's constructing a string with the $(IntermediateOutputPath) property and the %(Filename) well-known item metadata.

The well-known item metadata should be available for any item and includes most notably the path to the item

MetaData        Example     
%(FullPath)     C:\MyProject\Source\Program.cs
%(RootDir)      C:\
%(Directory)       MyProject\Source\
%(Filename)                         Program
%(Extension)                               .cs
2
Megha On

I am not sure if these little language has a special name. From what I know these are ways defined to extract or display values of items or metadata that items may contain.

For eg: @ symbol is used the get the value of any ItemType. For item list transformations @(SourceFiles -> '%(Filename).obj') is used.

Check out this link for more information https://msdn.microsoft.com/en-us/library/dd393573.aspx

See the sections from Examining Item Type Values.