Zain Rizvi
Zain Rizvi

Reputation: 24636

How to add an ItemList to a default ItemDefinitionGroup metadata in MSBuild?

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

Upvotes: 2

Views: 1344

Answers (1)

Zain Rizvi
Zain Rizvi

Reputation: 24636

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>

Upvotes: 6

Related Questions