Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsBuild WriteLinesToFile Task on multiple files

Tags:

msbuild

I have the following in a AfterGet target in TFS.

<ItemGroup>
  <AssemblyInfoFiles Include="$(SolutionRoot)\**\*assemblyinfo.cs" />
</ItemGroup>
<WriteLinesToFile
        File="@(AssemblyInfoFiles)"
        Lines="AssemblyInformationalVersion(&quot;$(LabelName)&quot;)]"
        Overwrite="false"/>

The ItemGroup includes multiple files, but the WriteLinesToFile only expects a single file.

And logs the following error: error MSB4094: "XXXX;YYYY;ZZZZ" is an invalid value for the "File" parameter of the "WriteLinesToFile" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem".

How do I pass each item from the ItemGroup into the WriteLinesToFile Task?

like image 578
Morten Lyhr Avatar asked Sep 01 '25 22:09

Morten Lyhr


1 Answers

You can use batching : try

<ItemGroup>
  <AssemblyInfoFiles Include="$(SolutionRoot)\**\*assemblyinfo.cs" />
</ItemGroup>
<WriteLinesToFile
        File="%(AssemblyInfoFiles.FullPath)"
        Lines="AssemblyInformationalVersion(&quot;$(LabelName)&quot;)]"
        Overwrite="false"/>

Hope it helps !

like image 123
Cédric Rup Avatar answered Sep 04 '25 23:09

Cédric Rup