Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem here is you are using the <code>ReadLinesFromFile</code> task in a manner it wasn't intended.</p> <blockquote> <p><strong>ReadLinesFromFile Task</strong><br> Reads a list of <em>items</em> from a text file.</p> </blockquote> <p>So it's not just reading all the text from a file, it's reading individual items from a file and returning an item group of ITaskItems. Whenever you output a list of items using the <code>@()</code> syntax you will get a separated list, the default of which is a semicolon. This example illustrates this behavior:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"&gt; &lt;ItemGroup&gt; &lt;Color Include="Red" /&gt; &lt;Color Include="Blue" /&gt; &lt;Color Include="Green" /&gt; &lt;/ItemGroup&gt; &lt;Target Name="Build"&gt; &lt;Message Text="ItemGroup Color: @(Color)" /&gt; &lt;/Target&gt; &lt;/Project&gt; </code></pre> <p>And the output looks like this:</p> <pre><code> ItemGroup Color: Red;Blue;Green </code></pre> <p>So while the best solution to your problem is to write an MSBuild task that reads a file into a <em>property</em> as a string an not a list of items, that's really not what you asked for. You asked if there was a <em>way</em> to put them back, and there is using <a href="http://msdn.microsoft.com/en-us/library/ms171476.aspx" rel="noreferrer">MSBuild Transforms</a>.</p> <p>Transforms are used to create one list from another and also have the ability to transform using a custom separator. So the answer is to transform your list read in using <code>ReadItemsFromFile</code> into another list with newlines. Here is an example that does just that:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"&gt; &lt;ItemGroup&gt; &lt;File Include="$(MSBuildProjectDirectory)\Test.txt" /&gt; &lt;/ItemGroup&gt; &lt;Target Name="Build"&gt; &lt;ReadLinesFromFile File="@(File)"&gt; &lt;Output TaskParameter="Lines" ItemName="FileContents" /&gt; &lt;/ReadLinesFromFile&gt; &lt;Message Text="FileContents: @(FileContents)" /&gt; &lt;Message Text="FileContents Transformed: @(FileContents-&gt;'%(Identity)', '%0a%0d')" /&gt; &lt;/Target&gt; &lt;/Project&gt; </code></pre> <p>Test.text looks like:</p> <pre><code>Red Green Blue </code></pre> <p>And the output looks like this:</p> <pre><code>[C:\temp]:: msbuild test.proj Microsoft (R) Build Engine Version 3.5.21022.8 [Microsoft .NET Framework, Version 2.0.50727.1433] Copyright (C) Microsoft Corporation 2007. All rights reserved. Build started 11/8/2008 8:16:59 AM. Project "C:\temp\test.proj" on node 0 (default targets). FileContents: Red;Green;Blue FileContents Transformed: Red Green Blue Done Building Project "C:\temp\test.proj" (default targets). Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:00.03 </code></pre> <p>What's going on here is two things.</p> <pre><code>@(FileContents-&gt;'%(Identity)', '%0a%0d') </code></pre> <ul> <li>We are transforming the list from one type to another using the same values (<code>Identity</code>) but a custom separator <code>'%0a%0d'</code></li> <li>We are using <a href="http://msdn.microsoft.com/en-us/library/ms228186.aspx" rel="noreferrer">MSBuild Escaping</a> to escape the line feed (<code>%0a</code>) and carriage return (<code>%0d</code>)</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload