xofz
xofz

Reputation: 5660

Get list of dlls in a directory with MSBuild

The following gives me only 1 file, the exe:

<ItemGroup>
      <AssembliesToMerge Include="$(MSBuildProjectDirectory)\App\bin\Release\*.*" Condition="'%(Extension)'=='.dll'"/>
      <AssembliesTomerge Include="$(MSbuildProjectDirectory)\App\bin\Release\App.exe"/>
</ItemGroup>

If I remove the Condition attribute, AssembliesToMerge contains all the files in the directory--dlls and otherwise. What am I doing wrong?

I am testing this via the ILMerge MSBuildCommunityExtensions Task. If there is a way to directly print the items in the ItemGroup, then that might help to ensure it's an issue with the Condition attribute.

Upvotes: 0

Views: 843

Answers (1)

Julien Hoarau
Julien Hoarau

Reputation: 49970

Just use a wildcard in Include to filter dll files (Items wildcard)

<ItemGroup>
  <AssembliesToMerge Include="$(MSBuildProjectDirectory)\App\bin\Release\*.dll"/>
  <AssembliesTomerge Include="$(MSbuildProjectDirectory)\App\bin\Release\App.exe"/>
</ItemGroup>

I think it doesn't work using the Condition attribute because Item metadatas aren't set yet during creation, so %(Extension) is empty.

Upvotes: 2

Related Questions