0

Assume the following ItemGroup structure:

<ItemGroup>
  <BinaryFiles Include="C:\">
    <Binary>a.dll</Binary>
    <Binary>b.dll</Binary>
  </BinaryFiles>
  <BinaryFiles Include="D:\">
    <Binary>my.ddl</Binary>
  </BinaryFiles>
</ItemGroup>

I need to flatten this to a string like this:

C:\a.dll;C:\b.dll;D:\my.dll

How would I do that? If it's not possible, is there a better way to do it?

Howie
  • 25
  • 3

1 Answers1

0

A metadata value can have only one value. Multiple definitions and updates will override the value, so the "C:\" item will only have b.dll as Binary metadata.

If there is only one element in the metadata then @(BinaryFiles->'%(Identity)%(Binary)') would yield the result you wanted.

However, since you are using file based logic, you are better off using a BinaryFiles item for each item:

<BinaryFiles Include="C:\*.dll" />
<BinaryFiles Include="D:\*.dll" />

This will scan for all the dll files. You can even use D:\**\*.dll to scan recursively. Then you can use @(BinaryFiles->'%(FullPath') to get the list of all absolute paths.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • Thanks for the answer. I wanted to avoid to repeat the common path every time. Is there a better way which lets me specify the path once for a bunch of files, and them list the files in a variable number of tags? – Howie Aug 26 '17 at 15:56
  • Do you want to specify them all? the above example would search for files matching the pattern (`*.dll`) – Martin Ullrich Aug 26 '17 at 16:00
  • I want to selectively add specific files, not all files matching a pattern. There can be a lot more DLL files in a directory than I want to specify. – Howie Aug 26 '17 at 16:05