MsBuild WriteLinesToFile Task for Multiple Files

I have the following in targetGet in TFS.

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

An element group includes several files, but WriteLinesToFile expects only one file.

And it 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 to a parameter of type "Microsoft.Build.Framework.ITaskItem".

How to pass each item from an ItemGroup to a WriteLinesToFile task?

+3
source share
1 answer

You can use batch processing: try

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

Hope this helps!

+9
source

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


All Articles