'Error deleting locked file on publishing a webservice over Visual Studio

I'd like to publish a webservice in visual studio 2022 over the context function "Publish..." to a remote server folder, on which internet information services (iis) is running.

If visual studio 2022 published the webservice to the remote server folder the first time, there are no errors. But when i publish the webservice a second or a third time after a few days i got the following error.

...
>*Error deleting file 'bin'.  Unable to delete 'bin'.  Access denied*
...

I have checked the folder and found a file 'example.dll' in the folder 'bin' from my webservice, which can not be deleted.

The not deletable file 'example.dll' is used by w3wp.exe an iis worker process.

I have to restart in iis the application pool of the webservice to unlock the file 'example.dll'.

But the problem is, that other webservice are running in the application pool and this leads to errors by the other webservices.

Is there a other way to unlock or to delete the file on publishing the webservice over visual studio 2022?



Solution 1:[1]

I'm sure you could write a script or something to auto recycle the app pool on publish, but most of the time if the service is in use you will need to recycle/stop the pool to release that dll.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JBatstone