2
votes

I am using TFS v2015 to deploy a web application to a remote server. Due to the way our project is structured (as a web site project) the build ends up creating a separate DLL for each .cs. The names of the DLL files are random and change on each deploy. This has resulted in 25,000+ files in the bin folder with names like "App_Web_0bbazvic.dll".

What I would like to do is, before copying files to target machine, delete all files matching the pattern "/bin/app_code_*.dll" from the remote bin directory.

I have considered using the "Machine File Copy" with the option "clean target" enabled, but I don't want to delete the entire directory. I can explain my reasons for this in more detail if requested.

I am also considering the "Power Shell on Target Machine" task. Any suggestions would be appreciated. Also, the remote server is not in the same domain as the build agent.

2

2 Answers

2
votes

You can do this using simple Delete Task without even going to PowerShell assuming your files are located the same location where the agent is running.

Like this

enter image description here

For deleting files in remote path you can use the Remote delete task

Like this enter image description here

1
votes

You can add something like this as an inline script if you are able to use WinRM.

Get-ChildItem -Path C:\Path\To\Files -recurse -include app_code_*.dll | Remove-item

https://docs.microsoft.com/en-us/vsts/pipelines/tasks/deploy/powershell-on-target-machines?view=vsts