can't publish file due to file in use by IIS
Completed
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(154,5): error MSB3027: 无法将“obj\Debug\netcoreapp3.1\Chirp.dll”复制到“C:\WWW\Chirp\Chirp.dll”。超出了重试计数 10。失败。
C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(154,5): error MSB3021: 无法将文件“obj\Debug\netcoreapp3.1\Chirp.dll”复制到“C:\WWW\Chirp\Chirp.dll”。The process cannot access the file 'C:\WWW\Chirp\Chirp.dll' because it is being used by another process.
my IIS site dictory is C:\WWW\Chirp ,when I stop IIS, publish successed, how to resolve it, thanks.
Please sign in to leave a comment.
Hello!
It appears that you run "dotnet publish" command to publish an application which is already deployed and running. Unfortunately, it appears that publish command has no built-in logic to stop IIS resources during deployment; TeamCity is just invoking the command with no extra logic involved to integrate with IIS either. As far as I could see, MS-recommended way to stop an application/site during the deployment is to put a app_offline.htm file during deployment so that IIS will stop the resource automatically (and remove it as a last step). Please see the example at https://stackoverflow.com/questions/42836465/publishing-a-dotnet-application-thats-already-running.
Alternatively, you can add a command line step before and after deployment to stop the resource and start it after deployment is over (or rollback if necessary).
It worked, thanks a lot, P