How I Deploy Code
I use two (three?) tools on a daily basis to build and deploy code.
1. Robocopy2. MSBuild
3. Windows PowerShellRobocopy is a newer command line directory replicator available out of the box in Windows Server 2008 and up as well as Vista and up. You can get it for XP and Server 2003 as part of the Windows Resource Kit as well. Basically you point it to a directory to copy from and a directory to copy to and it will copy the entire contents of said directory. That in itself isn't enough to warrant much praise, but it also includes robust facilities for retrying copying in the case of network or disk failure. Before developing my new build and deploy process, I would routinely use the Publish Website wizard in Visual Studio to copy my application to a local directory, then used windows explorer to copy the files to the production share. Needless to say, this is not a good way of doing things. For one, the windows explorer copy function sucks. It sucks a lot. It doesn't care what's newer or older or the status of the network or disk. If you're 1 minute away from finishing an hour long copy (not unusual for an Explorer copy) and the network goes kaput, you're screwed -- try figuring out where it left off. Robocopy will detect the problem and pause, retrying a configurable amount of times. It's also much, much, much faster than an Explorer copy due to the fact that it skips overwriting files that are older or the same age than the ones in the destination. It also seems to be written from the ground up to be faster at copying files. I can't lavish enough praise on Robocopy. It's really a must have tool for Windows developers.MSBuild is basically Microsoft's version of 'make' or 'ant'. It's a configurable utility to build .NET applications from the command line which can be scripted and customized. Personally I don't use a lot of the functionality, and in fact, I could probably get away with just batch scriping the csc compiler, but using MSBuild lets me set up different targets in case I want to clean or force a rebuild (I normally always just rebuild). PowerShell is what the command line in Windows should be: a scriptable interface much like the Bash shell on Linux systems. It's not something that I can't live without, but I like it for the colored output and larger default window. So, how do I use all three of these together? Batch scripts. Yep, the humble batch script:This is my BuildFull script. It calls MSbuild to clean and then rebuild my entire solution, then Robocopy to copy the built web app to a deploy directory. You could even point a local instance of IIS to the deploy directory to do a final end to end test or whatever. Notice I have Robocopy set up to exclude a bunch of junk such as the subversion folders, build folders, cache files, configuration files, project files, user-specific settings, debug databases, etc. I also ignore all source code; we don't need it. And here's my deploy script. It copies files from my local deploy directory to the production share. Since we have a load-balanced server, I then make sure both shares are up to date by copying one to the other including the Web.config file in case I manually deployed it. A lot of people think there's some sort of mystic art to making the perfect build and deploy routine when there just isn't. Setting up scripts to handle your deployments is an absolutely necessity to keeping your sanity.



