Remove trailing slash in MSBuild / Convention file name generation

I am trying to find a collection of assemblies based on the following convention in a directory:

{SubDirName}\{SubDirName}.dll

I started by creating an MSGuild ItemGroup [by batch processing another ItemGroup in a .RecursiveDir section].

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

Each element has a trailing slash, that is:

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

He speaks:

SubDir1\;SubDir2\;SubDir3\

Now I want to generate a set of file names from this list.

The problem is that:

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

Forms:

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

I do not need slashes before the period in .dll.

What is the cleanest way to achieve this?

I know there is a HasTrailingSlash expression statement, but there are no signs of the RemoveTrailingSlash task in OOTB tasks ?. I am not fussy about the version of MSBuild.

+3
source share
2 answers

MSBuild.NET .NET 4.0 "\." "." s .

(, , )

0

<AssembliesByConvention Include="@(Dirs -> '%(Identity)%(Identity).dll')" Condition="HasTrailingSlash(%(Identity))" />
<AssembliesByConvention Include="@(Dirs -> '%(Identity)\%(Identity).dll')" Condition="!HasTrailingSlash(%(Identity))" />
+1

Source: https://habr.com/ru/post/1755965/


All Articles