I have a list of files generated on each build inside a directory C:\BuildArtifacts
The Contents of a directory looks like this:
TestBuild-1.0.0.1.zip
TestBuild-1.0.0.2.zip
TestBuild-1.0.0.3.zip
TestBuild-1.0.0.4.zip
TestBuild-1.0.0.5.zip
TestBuild-1.0.0.6.zip
Now, with each incremental build, I just want to retain two recent artifacts and delete the rest. So, in this example, I want to retain TestBuild-1.0.0.5.zip and TestBuild-1.0.0.6.zip
How can I do it with MSBuild?
Note:
I have managed to fetch the above list in an item
<Exec WorkingDirectory="$(Artifacts)\.." Command="dir /B /A:-D /O:-N" Outputs="ArchiveFileList" />
Well, we wrote a custom task to sort the files by their name and then output the list of the files to delete (excluding the first two in the list) into an
ItemCustom Task:
Usage: