Use Rsync to Copy Your ASP.NET Website

If you’ve ever tried to copy the source files from a Visual Studio 2005 ASP.NET solution, especially if you’re using TFS and Resharper, you’ll have probably noticed all great steaming heaps of fluff and nonsense these tools leave all over your hard drive. Not to mention all the built assemblies lurking in your bin/Debug folders.

If you have a unix/linux/apple machine handy, or have at least had the sense to instal cygwin or coLinux on your quaint old PC, then give this a rumble.

Prepare a file with the inclusion / exclusion rules for the files / folders you want to copy. For my solution, it looks like this:

  • *.cs
  • **/lib/.
  • *.csproj
  • *.sln
  • *.resx
  • *.jgp
  • *.gif
  • *.gif
  • *.aspx
  • *.ashx
  • *.js
  • *.ascx
  • *.config
  • *.xml
  • *.txt
  • *.html
  • *.htm
  • *.dbp
  • *.sql
  • */
  • *

There are a few fascinating points to note about this file:

  • The lines that begin with a ‘+’ character are include rules.
  • The second line copies anything in a /lib folder, which is where we keep dependencies in my world
  • The second-to-last line tells rsync to copy every folder. Without this, the last line would exclude all the folders (rsync works its way through the folder tree recursively) and you’d never get to the files you’d mentioned above. Read that bit again, it’s hard to understand at first, but important.
  • The last line excludes everything else.

Now fire up your terminal, and invoke the magic of rsync:

rsync -av –exclude-from=files.txt source/Projects/Widgets/ target/Projects/Widgets/

Which means

  • copy all files (recursively)
  • write verbose output

And there you have it. Yet more unix joy.