If you have worked on a large Commerce Server implementation, you have likely built a custom pipeline component or two. This makes you part of a very special band of brothers (requires Facebook login). It also means that you have probably seen your fair share of the build error "Unable to copy file ... The process cannot access the file XYZ" (pictured below in all it's namespace censored glory)...

This error usually occurs when you build pipeline component project, having just run a pipeline that contains the same physical component (or another component in the same assembly). The reason it occurs is that the process hosting your website (in my case w3wp.exe) has an open file handle to the assembly containing your pipeline component. Hence you can't copy over it :(
In the past I have resolved this using one of the following methods:
However, all of these involve what I call micro-tedium. Micro-tedious tasks are those computing tasks that are so small that they appear insignificant, but in reality suck the life out of you (like the Large Hadron Collider is also probably doing right now).
Anyway, I digress.
My Slightly Funky but Practical Solution to "The Process Cannot Access the File" Tedium
IIS7 ships with a new tool called Appcmd.exe. It is a command line tool that lets you do useful stuff like create and configure sites, view information about worker processes and start and stop application pools!
So, for pain free pipeline component development, use appcmd.exe in the pre and post-build events of your pipeline component project, to stop and start the application pool that hosts your Commerce Server site. My build event commands look like this (you will need to replace DefaultAppPool with the name of the Application Pool your Commerce Server site is running in):
Configuring your build event commands like this results in the following occurring in order when you build your pipeline component project:
- Before the build, the application pool is stopped.
- Your project builds.
- After the build the application pool is started again.
It works for me. Does it work for you? Any elegant(er) solutions out there?
Important Note about Exit 0: The exit 0 command is included so that the return code is always success, even if appcmd has a non-success return code. I do this because Appcmd will fail to stop the application pool, if the application pool is not already running. This would then cause your build to fail. The exit 0 command stops that happening. If you have other commands in your build event, exit 0 could mask their failure.
Stuck on IIS 6? If you are stuck on IIS 6 you may want to hack up something similar using one of the IIS 6 Command Line Tools (I think it is possible!).
Appendix: Paste-able Version of the Appcmd Commands Used
%systemroot%\system32\inetsrv\appcmd.exe stop apppool DefaultAppPool
exit 0
%systemroot%\system32\inetsrv\appcmd.exe start apppool DefaultAppPool
exit 0