Read text file and split every line in MSBuild RRS feed

  • Question

  • Hi
    I am stuck at the following issue I have in MSBuild.
    I have a text file (buildsolutions1.txt) containing the list (line by line) with all the solutions I need to build and the related developers emails separated by comma :


    I need to read this file line by line,compile each solution and in case it fails –send email to related developer(s)

    My idea is to create an item group Lines where every item is a line from this file and it has 2 metadata values:
    Solution –first part of the line until comma
    Emails –second part of the line from comma to the end of line

    So I created a Property Grroup and a target ReadSolutions like below.

    I read the file line by line but I do not know how to set the metadata for each line item:
          <Emails>SecondPartOfTheCurrentLine(%(LinesFromFile.Identity)) </Emails>

    This syntax does not work:


    Maybe someone would know how to set the metadata correctly or maybe has another approach to this task.

    Here is the code:

       <!-- Default working folder -->
      <RootFolder Condition=" '$(RootFolder)' == '' " >c:\ff\</RootFolder>
      <BuildSolutionsFile >buildsolutions1.txt</BuildSolutionsFile>
       <BuildSolutionsFileFullPath >$(RootFolder)$(BuildSolutionsFile)</BuildSolutionsFileFullPath>

    <Target Name="ReadSolutions">
      <Message Text=" Build solutions text file is : $(BuildSolutionsFileFullPath)" />

    <!—Read the file and store each line as an item into  LinesFromFile  item group-->
        File="$(BuildSolutionsFileFullPath)" >

       <Message Text="Current line : %(LinesFromFile.Identity)" />
      <Message Text="===================================" />

    <!—Create  the other item group where each item is a line and has the metadata Solution and Emails -->

        <Lines Include="%(LinesFromFile.Identity)" >
          <Emails>SecondPartOfTheCurrentLine(%(LinesFromFile.Identity)) </Emails>



      <Message Text="All the Lines :%0A@(Lines,'%0A')" />


    Thursday, January 30, 2014 2:33 PM


  • Thank you!

    I found the solution here,maybe it would help someone else:



    • Edited by Teognost Friday, January 31, 2014 12:16 PM
    • Marked as answer by Anna Cc Tuesday, February 4, 2014 1:52 AM
    Friday, January 31, 2014 12:15 PM

All replies