Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 71151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:50:34+00:00 2026-05-10T19:50:34+00:00

When I do a ReadLinesFromFile on a file in MSBUILD and go to output

  • 0

When I do a ReadLinesFromFile on a file in MSBUILD and go to output that file again, I get all the text on one line. All the Carriage returns and LineFeeds are stripped out.

<Project DefaultTargets = 'Deploy' xmlns='http://schemas.microsoft.com/developer/msbuild/2003' > <Import  Project='$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets'/>  <ItemGroup>     <MyTextFile Include='$(ReleaseNotesDir)$(NewBuildNumber).txt'/> </ItemGroup>  <Target Name='ReadReleaseNotes'>     <ReadLinesFromFile         File='@(MyTextFile)' >         <Output             TaskParameter='Lines'             ItemName='ReleaseNoteItems'/>     </ReadLinesFromFile> </Target>  <Target Name='MailUsers' DependsOnTargets='ReadReleaseNotes' >     <Mail SmtpServer='$(MailServer)'         To='$(MyEMail)'         From='$(MyEMail)'         Subject='Test Mail Task'         Body='@(ReleaseNoteItems)' /> </Target> <Target Name='Deploy'>     <CallTarget Targets='MailUsers' /> </Target>  </Project> 

I get the text from the file which normally looks like this

- New Deployment Tool for BLAH  - Random other stuff()'' 

Coming out like this

- New Deployment Tool for BLAH;- Random other stuff()'' 

I know that the code for ReadLinesFromFile will pull the data in one line at a time and strip out the carriage returns.

Is there a way to put them back in? So my e-mail looks all nicely formatted?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:50:35+00:00Added an answer on May 10, 2026 at 7:50 pm

    The problem here is you are using the ReadLinesFromFile task in a manner it wasn’t intended.

    ReadLinesFromFile Task
    Reads a list of items from a text file.

    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 @() syntax you will get a separated list, the default of which is a semicolon. This example illustrates this behavior:

    <?xml version='1.0' encoding='utf-8'?> <Project DefaultTargets='Build'    xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion='3.5'>      <ItemGroup>         <Color Include='Red' />         <Color Include='Blue' />         <Color Include='Green' /> </ItemGroup>  <Target Name='Build'>         <Message Text='ItemGroup Color: @(Color)' /> </Target>  </Project> 

    And the output looks like this:

      ItemGroup Color: Red;Blue;Green 

    So while the best solution to your problem is to write an MSBuild task that reads a file into a property as a string an not a list of items, that’s really not what you asked for. You asked if there was a way to put them back, and there is using MSBuild Transforms.

    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 ReadItemsFromFile into another list with newlines. Here is an example that does just that:

    <?xml version='1.0' encoding='utf-8'?> <Project DefaultTargets='Build' xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion='3.5'>      <ItemGroup>         <File Include='$(MSBuildProjectDirectory)\Test.txt' />     </ItemGroup>      <Target Name='Build'>         <ReadLinesFromFile File='@(File)'>             <Output TaskParameter='Lines' ItemName='FileContents' />         </ReadLinesFromFile>          <Message Text='FileContents: @(FileContents)' />         <Message Text='FileContents Transformed: @(FileContents->'%(Identity)', '%0a%0d')' />     </Target>  </Project> 

    Test.text looks like:

    Red Green Blue 

    And the output looks like this:

    [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 

    What’s going on here is two things.

    @(FileContents->'%(Identity)', '%0a%0d')    
    • We are transforming the list from one type to another using the same values (Identity) but a custom separator '%0a%0d'
    • We are using MSBuild Escaping to escape the line feed (%0a) and carriage return (%0d)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load a list of filenames from a text file and then
We have a process that runs prior to our nightly builds. If the process
I'm trying to use MSBuild to read in a list of files from a
I'm using MSBuild to customize the build process of Visual Studio, WiX, SandCastle, ...
I need to read the XML from the file. I use following code: <ItemGroup>
I have a target in my build script that will send an email with
After years of programming, we all have a set of small functions used as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.