Morten Lyhr
Morten Lyhr

Reputation: 95

MsBuild WriteLinesToFile Task on multiple files

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?

Upvotes: 4

Views: 4843

Answers (1)

C&#233;dric Rup
C&#233;dric Rup

Reputation: 15928

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 !

Upvotes: 10

Related Questions