What is the difference between @ and $ and% in MSBuild?

What are the differences when accessing variables in MSBuild. For example, in the following case, @ and $ , as well as % .

 <Copy SourceFiles="@(Files)" DestinationFolder="$(TempBuildDir)\%(RecursiveDir)"> <Output TaskParameter="CopiedFiles" ItemName="DeployFiles" /> </Copy> 
+6
source share
2 answers

$ denotes access to the property (some variable containing a simple value)

@ for an item, which is usually a group of files with attached metadata named

% indicates access to item metadata. There are known metadata (e.g. RecursiveDir, see Definition in msdn) that are automatically bound to an element, or you can attach your own metadata when defining your elements

let's say you define @ (files) as follows:

 <ItemGroup> <Files include='c:\source\**\*.*'> <!-- all files in all subfolder in c:\source --> <Color>Blue</Color> <!-- attach metadata color = 'Blue' to these files --> </Files> <Files include='c:\source2\**\*.*'> <!-- all files in all subfolder in c:\source2 --> <Color>Red</Color> <!-- attach metadata color = 'Red' to these files --> </Files> </ItemGroup> 

if c: \ source contains the files 1.txt, b / 2.dll, c / 3.xml and c: \ source2 contains /4.exe, @ (files) is formed as follows

  • file c: \ source \ 1.txt, with metadata color = 'Blue' and RecursiveDir = ''

  • file c: \ source \ b \ 2.dll with metadata color = 'Blue' and RecursiveDir = 'b'

  • file c: \ source \ c \ 3.xml, with metadata color = 'Blue' and RecursiveDir = 'c'

  • file c: \ source2 \ a \ 4.exe, with metadata color = 'Red' and RecursiveDir = 'a'

If you define TempBuildDir like this

 <PropertyGroup> <TempBuildDir>c:\temp<TempBuildDir> </PropertyGroup> 

You have some kind of variable containing a simple value: c: \ temp

Your examples read as follows: copy all the files defined in the File element in the directory, which is formed by combining the value of the TempBuildDir variable with the recursive directory in which you found the file.

The result is:

  • C: \ Temp \ 1.txt

  • C: \ Temp \ b \ 2.dll

  • C: \ Temps \ s \ 3.xml

  • C: \ Temp \ a \ 4.exe

+11
source

Here is a complete list of special characters:

http://msdn.microsoft.com/en-us/library/bb383819.aspx

+4
source

Source: https://habr.com/ru/post/891157/


All Articles