<p>I'm using a native DLL (FastImage.dll) in a C# ASP.NET Web Service that sometimes locks (can't delete it---says access denied); this requires stopping IIS to delete the DLL. The inability to delete this DLL in the bin folder of my published Web Service prevents me from publishing successfully (even though it thinks it published successfully!), which makes development and fixing the bug difficult (especially when it just happily runs old code since my changes may not be reflected on the server!). Note that the bug causing the Web Service to bomb and lock up the DLL is in my code, which is outside of said DLL, so I think this is a more general problem than just the FreeImage library (not to bring them any heat).</p>

<ol>
<li>Has anyone experienced this?</li>
<li>Is there a way to make sure that when it says "Publish succeeded" from the VS IDE that it really means it, or to run sort of script to check that the files are really deleted before it attempts to Publish (like a pre-build step in VC++). (Right now I manually delete the files before publishing to make sure that I know the DLLs were replaced, instead of running old DLLs. It's still a problem, though if I can't delete the DLL.)</li>
<li>How would I detect whether a file was successfully deleted from a batch file? (so I can stop and start IIS if it fails)</li>
<li>Is it possible to stop and start IIS from a script (preferably from the Publish... action in the VS IDE) and if so, how?</li>
</ol>

[{'answer_id': 35501, 'author': 'tbreffni', 'author_id': 637, 'author_profile': 'https://Stackoverflow.com/users/637', 'pm_score': 0, 'selected': False, 'text': "<p>You could use the IISReset command line tool to stop/restart iis.  So you could write a simple batch file to stop iis, copy your files, and then restart iis.  I'm not sure how to integrate this with the VS publish feature however.</p>\n"}, {'answer_id': 47221, 'author': 'Jon', 'author_id': 4764, 'author_profile': 'https://Stackoverflow.com/users/4764', 'pm_score': 3, 'selected': True, 'text': '<p>Using the IISReset command line tool will only restart IIS on the local machine, not on a remote server to which you are publishing.</p>\n\n<p>Assuming that you are publishing to a Windows 2003 server, I\'d suggest trying the slightly less drastic step of stopping and restarting the IIS AppPool in the web site or virtual folder in which the web service runs.  (That way you are not taking all sites that run on the target server offline.)  This too assumes that the web service runs in its own app pool.  Ideally it should, so you keep it isolated.</p>\n\n<p>I\'d recommend getting away from using the Publishing process and to look into using a Web Deployment Project.  Here is a post on ScottGu\'s blog detailing <a href="http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx" rel="nofollow noreferrer" title="VS 2005 Web Deployment Projects">VS 2005 Web Deployment Projects</a>.</p>\n\n<p>The advantage to the Web Deployment Project approach is that it provides you with all the power and capability of MSbuild, as it is really just a convenience wrapper around MSBuild.  Here\'s a post from the MSBuild team about <a href="http://blogs.msdn.com/msbuild/archive/2005/10/12/480212.aspx" rel="nofollow noreferrer">pre-build and post-build capabilities</a></p>\n\n<p>Hope this helps.</p>\n'}]
['https://Stackoverflow.com/questions/35479', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2543/']