5

I'm trying to search for a set of assemblies based on the following convention within a directory:

{SubDirName}\{SubDirName}.dll

I've started by creating an MSBuild ItemGroup [by batching another ItemGroup on the .RecursiveDir portion].

<AllAssemblies Include="$(SourceDirectory)\**\Test.*.dll" />
<Dirs Include="@(AllAssemblies->'%(RecursiveDir)')"/>

Each item has a trailing slash, i.e.:

<Message Text="@(Dirs)"/>

Says:

SubDir1\;SubDir2\;SubDir3\

Now, I want to generate a set of filenames from this list.

The problem is that:

<AssembliesByConvention Include="@(Dirs -> '%(Identity)\%(Identity).dll')" />

Generates:

SubDir1\\SubDir1\.dll;SubDir2\\SubDir2\.dll;SubDir3\\SubDir3\.dll

I dont want the slashes before the period in .dll.

What's the cleanest way to achieve this?

I know there's a HasTrailingSlash expression operator, but there's no sign of a RemoveTrailingSlash task in the OOTB Tasks?. I'm not fussy about the MSBuild version required.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249

2 Answers2

1

Have you tried

<AssembliesByConvention Include="@(Dirs -> '%(Identity)%(Identity).dll')" Condition="HasTrailingSlash(%(Identity))" />
<AssembliesByConvention Include="@(Dirs -> '%(Identity)\%(Identity).dll')" Condition="!HasTrailingSlash(%(Identity))" />
Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • Thanks Sayed. Unfortunately, the value has a trailing slash (as it comes from RecursiveDir), and I want to embed it into a filename (I am getting double backslashes between dir bits and your remedy would cure that - but of course that's silently ignored anyway - remember this isnt for pretiness, its coz it dont work!). – Ruben Bartelink Aug 04 '10 at 07:49
0

You can use MSBuild's .NET methods support in .NET 4.0 to replace the "\."s with "."s in the final result.

(This would at least solve my original problem)

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249