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

本小妞迷上赌 提交于 2019-12-08 02:47:35

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/6780985/how-to-add-an-itemlist-to-a-default-itemdefinitiongroup-metadata-in-msbuild

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!