2

I'm trying to add all the files in a given directory to the ClCompile metadata's ForcedUsingFiles parameter.

I'm using the following code:

<ItemGroup>
  <ForcedUsingFilesList Include="c:\path\to\files\*" />
</ItemGroup>
<ItemDefinitionGroup>
  <ClCompile>
    <ForcedUsingFiles>@(ForcedUsingFilesList)</ForcedUsingFiles>
  </ClCompile>
</ItemDefinitionGroup>

But I'm getting the error

The value "@(ForcedUsingFilesList)" of metadata "ForcedUsingFiles" contains an item list expression. Item list expressions are not allowed on default metadata values.

Any idea how I can work around this error?

Thanks

Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133

1 Answers1

6

Ah, looks like I needed to add an extra layer of indirection to convert the ItemList to a Property. Then I could stick the property into the ItemDefinitionGroup.

The following code did the trick, wish there was a more direct way to do this though:

  <ItemGroup>
    <ForcedUsingFilesList Include="c:\path\to\files\*" />
  </ItemGroup>
  <PropertyGroup>
    <ForcedUsingFilesList2>
        @(ForcedUsingFilesList->'%(FullPath)')
    </ForcedUsingFilesList2>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <ClCompile>     
      <ForcedUsingFiles>$(ForcedUsingFilesList2)</ForcedUsingFiles>
    </ClCompile>
  </ItemDefinitionGroup>
Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133
  • @ZimiRizvi Is there a way to do this without the intermediate `PropertyGroup`? I'm trying to do something almost identical here: http://stackoverflow.com/q/26801753/2642059 – Jonathan Mee Nov 07 '14 at 15:59
  • @Jonathan-Mee I don't think there is. If it's possible, I don't know about it – Zain Rizvi Nov 09 '14 at 12:23
  • @ZimiRizvi If you have the time over the next couple days to enter this as an answer to: http://stackoverflow.com/q/26801753/2642059 I think that's as close as I'm going to get to a right answer. – Jonathan Mee Nov 09 '14 at 13:01