Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

.net - Copy-Item : The process cannot access the file 'dll' because it is being used by another process

I have a script to copy all artifact dotnet to remote server (from Jenkins server to IIS folder on remote server) for Deploy Stage like below:

#Parameters
param($userName, $passWord, $serverName, $deployFolder, $destinationFolder, $iisName)

$passwd = ConvertTo-SecureString $passWord -AsPlainText -Force
$creds = New-Object -typename System.Management.Automation.PSCredential -argumentlist $userName, $passwd

$session = New-PSSession -ComputerName $serverName -Credential $creds

#Stop IIS Application
Invoke-Command -Session $session -ScriptBlock { Import-Module IISAdministration; Stop-Website $args[0];}  -ArgumentList $iisName

Start-Sleep -s 200

#Copy new build to deploy folder
Copy-Item -Recurse -Force -Path $deployFolder -Destination $destinationFolder -ToSession $session

#Start IIS Application
Invoke-Command -Session $session -ScriptBlock { Import-Module IISAdministration; Start-Website $args[0];}  -ArgumentList $iisName

But sometimes I got issue Copy-Item : The process cannot access the file 'dll' because it is being used by another process.

Any ideas? Please let me know!
Thanks

question from:https://stackoverflow.com/questions/65896101/copy-item-the-process-cannot-access-the-file-dll-because-it-is-being-used-by

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As comments of Bruce Zhang, I add stop app pool to my script. It works.
Stop-WebAppPool -Name $args[0];


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...