none
is this ok? RRS feed

  • Question

  • I need to delete files. Those files are listed in a .log file and I also need to delete the logfile itself. I've written this like that... is this ok or would you do something different? Maybe adding anoter @ construct or whatever? (for example, writing the Condition and File parameter differently??) ... 

     

    <Target ...>
    	<ItemGroup>
    		<IDLDeleteFiles />
    	</ItemGroup>
    
    	<ReadLinesFromFile Condition="Exists('%(IDLDeletes.out)\%(IDLDeletes.Filename).log')" File="%(IDLDeletes.out)\%(IDLDeletes.Filename).log">
    		<Output TaskParameter="Lines" ItemName="IDLDeleteFiles"/>
    	</ReadLinesFromFile>
    
    	<Delete Files="@(IDLDeleteFiles)" />
    	<Delete Files="@(IDLDeletes->'%(out)\%(Filename).log')" />
    </Target>

    Rudolf


    • Edited by Rudolf Meier Thursday, November 14, 2019 9:07 PM
    Thursday, November 14, 2019 9:06 PM

Answers

  • ok, I know it now

    The difference between %(IDLDeletes.out)\%(IDLDeletes.Filename).log and @(IDLDeletes)->'%(out)\%(Filename).log is, that the first is a list of separate items (MsBuild loops over them and executes the target in which this is used as parameter for every of this items), while the second one is an item list and will be passed as one single object. The target that receives it then does have to support getting lists and does have to decide what to do with the list.

    In our case that's a) not what I want, because I want to execute everything as parallel as possible and b) it's even wrong, because the ReadLinesFromFile does not accept lists of files in the "File" parameter

    Rudolf

    • Marked as answer by Rudolf Meier Sunday, November 17, 2019 12:10 AM
    Sunday, November 17, 2019 12:10 AM

All replies

  • Hi, Rudolf Meier,

    Welcome to MSDN forum.

    Based on your code snippet, we suggest you could remove the "Condition". If the file doesn't exist, the target will skip it and continue to run without throwing error. And we could use propertygroup which could help us manager and modify better.

    Please refer this sample:

    <Target Name = "DeleteFile">
       <PropertyGroup>
         <IDLDeleteFiles>namelist.txt</IDLDeleteFiles>
         <Path>c:\Users\Administrator\source\repos\App11\App11</Path>
       </PropertyGroup>
    
       <ReadLinesFromFile File="$(IDLDeleteFiles)">
          <Output TaskParameter="Lines" ItemName="Files"/>
       </ReadLinesFromFile>
        
       <Delete Files="@(IDLDeleteFiles)"/>
       <Delete Files="@(Files->'$(Path)\%(FileName).log')" />
    </Target>

    Look forward to your feedback.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Friday, November 15, 2019 7:40 AM
  • I don't see your point...

    But maybe something like this would be a better way of doing it? I'm not sure... but I think the way how it is processed could be different. Maybe it's better or worse... I've no idea if this makes a difference at all.

    Instead of this

     <ReadLinesFromFile Condition="Exists('%(IDLDeletes.out)\%(IDLDeletes.Filename).log')" File="%(IDLDeletes.out)\%(IDLDeletes.Filename).log">

    I could (maybe) use this?

     <ReadLinesFromFile Condition="Exists('@(IDLDeletes)->'%(out)\%(Filename).log')" File="@(IDLDeletes)->'%(out)\%(Filename).log">

    ... is there a difference? Is one thing more efficient? Or is one even wrong?

    Rudolf

    Friday, November 15, 2019 3:56 PM
  • ok, I know it now

    The difference between %(IDLDeletes.out)\%(IDLDeletes.Filename).log and @(IDLDeletes)->'%(out)\%(Filename).log is, that the first is a list of separate items (MsBuild loops over them and executes the target in which this is used as parameter for every of this items), while the second one is an item list and will be passed as one single object. The target that receives it then does have to support getting lists and does have to decide what to do with the list.

    In our case that's a) not what I want, because I want to execute everything as parallel as possible and b) it's even wrong, because the ReadLinesFromFile does not accept lists of files in the "File" parameter

    Rudolf

    • Marked as answer by Rudolf Meier Sunday, November 17, 2019 12:10 AM
    Sunday, November 17, 2019 12:10 AM