5

Our Developers work with VisualStudio 2017

They use a Post-Build PowerShell function that I wrote, to publish the application to the correct destination.

Sometimes (1 out of 100 times) they get the following error:

Copy-Item : The process cannot access the file 'X:\xy\application.exe' because it is 
9>  being used by another process.

The thing is - it is not used by another process. Any other user (e.g me) can rename the file in the destination, delete it or whatever.

When the developer restarts his computer, he can publish the application without a problem.

So it looks like to me that his filesystem messes up something. we tried

taskkill /im explorer.exe /f && start "" explorer.exe but that didn't help.

If the developer looks into the destination with his explorer, the destination file is present for the developer, even after i deleted it.

How can this be? And how can we fix this?

The PowerShell function itself is very lightweight. It basically does this for deploying:

Write-Host "Starting Copying files to $d"
$Copy = Copy-Item $FilesToPublish $d -Force -Recurse
Write-Host "Finished Copying files to $d"

if specified (and it was specified), the function will also delete all locks for the destination

Get-SmbOpenFile -CimSession $Session | ? { $_.Path -like "$EndPath*" } | Close-SmbOpenFile -Force -PassThru

but the error also occurs, if we don't specify unlocking.

SimonS
  • 785
  • 4
  • 14
  • 29
  • I had some weird file locking issues in the past with Windows Explorer's preview pane. Someone had just marked a file in Explorer and the preview pane was enabled, nobody else could edit this file or rename or delete. Just a shot in the dark... – duenni Apr 08 '19 at 08:02
  • I recommend having the developer run Process Explorer when the issue occurs and then checking to see what process is holding the file, if any. https://www.techsupportalert.com/content/how-find-out-which-windows-process-using-file.htm – Persistent13 May 16 '19 at 15:13

1 Answers1

0

Robocopy has some options to redo copy of missing files. Hobocopy some kind of clone can make use of shadowcopy services to copy files even if in use.

https://www.raymond.cc/blog/copy-locked-file-in-use-with-hobocopy/

Peter
  • 115
  • 1
  • 8