locked
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 :

    Common\Common.sln,am@email,com
    ExcGw/ExcDataService.sln,pm@email.com;am@email,com;jk@email.com;mk@email.com;Ppp@email.com
    MessB/MessB/Message.sln,am@email,com
    RiskS/RiskS2.sln,jp@email.com;mz@email.com;mk@email.com;jk@email.com;ps@email.com

    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:
          <Solution>FirstPartOfTheCurrentLine(%(LinesFromFile.Identity))</Solution>
          <Emails>SecondPartOfTheCurrentLine(%(LinesFromFile.Identity)) </Emails>

    This syntax does not work:

          <Solution>%(LinesFromFile.Identity.Split(',')[0])</Solution>
          <Emails>%(LinesFromFile.Identity.Split(',')[1])</Emails>

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


    Here is the code:


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


    <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-->
      <ReadLinesFromFile
        File="$(BuildSolutionsFileFullPath)" >
        <Output
            TaskParameter="Lines"
            ItemName="LinesFromFile"/>
      </ReadLinesFromFile>

       <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 -->

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

        </Lines>

      </ItemGroup>

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



    </Target>


    Thursday, January 30, 2014 2:33 PM

Answers

  • Thank you!

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

    http://stackoverflow.com/questions/21460495/read-text-file-and-split-every-line-in-msbuild

    Regards


    • 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