Visual Studio–Publishing precompiled site but the old files magically re-appear on the server side

Posted by Blake on 2/10/2012

Scenario: You compile or recompile a site, then use Visual Studio’s built in “Publish” feature to send that precompiled site to a web server. You even choose “Delete all existing files before copy”. All the files are deleted and you’re new files are copied, except… the old files reappear on the server even though you don’t have local copies of them.

Why? IIS is caching the assemblies and when you copy them back out, IIS just replaces them with the cached copy.


  1. Restart IIS (the entire service, not just your web-site or the app pool). This will force all of the cached copies out of memory and allow you to deploy the new assemblies. This is the best sure fire way I’ve found to fix this problem.
  2. I’ve read this can work sometimes, but I haven’t had success: Delete all files in the %SystemRoot%Microsoft.NetFrameworkvTemporary ASP.Net Files directory. “v” will have some additional numbers behind it based on the framework version you want to clear.

Best Practice (in my opinion):

  1. Use the delete all existing files before copying option in the publish wizard. It doesn’t necessarily fix the above, but it makes sure that any legacy files that might not be needed anymore are removed.