MSDeploy with IIS6

One of the most common tasks an IIS admin can do (besides installing IIS and who really is still doing that if you’re doing virtualization) is to deploy code given to us by the developers.  In the olden days, this wasn’t too hard. You where given a batch file or maybe an MSI and you ran it on the one server that supported the applications.  But now, most applications have 2,3 or more servers that need to be worked on.  I’m a lazy admin. I hate doing things more than once so I was always looking for a way to sync multiple IIS servers. For a long time if you were using MS technologies, you had to either use nant or roll your own solution.  Some continued to use AppCenter 2000 but that’s a decade old!  Enter msdeploy.

I know that there are a lot of other blog posts out there on the Internet concerning Microsoft’s new deployment tool called Msdeploy, but most concern how it can be used with IIS7 applications. This isn’t surprising since it was really made for IIS7 and only really intended to interact with IIS6 so that you can migrate from IIS6 to IIS7. Well, it does a great job of synchronizing IIS6 applications as well!

All that you need to do is install MSdeploy on each server, enable the remote service – net start msdepsv – and simple command line like this:

  • msdeploy -verb:sync -source:metakey=lm/w3svc/1 -dest:metakey=lm/w3svc/1,computername=Server1

This will sync the files, AppPools, and IIS settings for your application. You can see all dependencies that will be sync via:

  • msdeploy.exe -verb:getDependencies,alltrigger -source:metakey=lm/w3svc/1

This is awesome stuff but there is one thing that was always missing from the list of dependencies for my applications.  And that was my GACed DLLs.  There isn’t a way for msdeploy to know if a assembly in the GAC is used by your application or not automatically.  The good thing is that Microsoft does give you the ability to sync GACed DLLs by running the following two commands:

  • msdeploy -verb:dump -source:gacAssembly="MyTestAssembly"
  • msdeploy -verb:sync -source:gacassembly="MyTestAssembly" -dest:metakey=lm/w3svc/1,computername=Server1

Again great stuff but it kind of sucks that you have to run two or more commands to sync your application if you have GACed DLLs. Never fear because Microsoft has thought of this as well.  What you need to do is to create a XML file that describes your application. In it, you can include everything that you want to sync – files, IIS6 metadata settings, GACed assemblies, etc . . . Then you just have to tell MSdeply to use that file as input and you’re done!

For example, MyApplication has been created on the Web Site #885762418 pointing to D:\Inetpub\myapplicationroot for its file location. It also has two dlls that it needs located in the GAC.  Then the XML would look like this:

<MyApplication>
  <metakey path="lm/w3svc/885762418" />
  <dirPath path="D:\Inetpub\myapplicationroot" />
  <gacAssembly path=’System.Web, Version=2.0.0.0, Culture=neutral, processorArchitecture=x86, PublicKeyToken=b03f5f7f11d50a3a’ />
  <gacAssembly path=’JPMCCommonServices, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL, PublicKeyToken=405319ba8665dd1a’ />
</MyApplication>

And the command to deploy this application would be

  • msdeploy.exe -verb:sync -source:manifest=custom.xml -dest:manifest=custom.xml,computername=Server1

I know that some people have strong opinions about XML but in this case it is very easy to use and makes our job as IT admins much simpler so we can focus on the other things that make our jobs challenging and fun.

One comment

  1. […] If you’re unable to configure DFS for whatever reason, you could use a scheduled task to run robocopy or xcopy to mirror. I would recommend robocopy /MIR as it’s easy to implement, and quite reliable. June 5, 2010 12:28 pm Justin Scott +1 for robocopy if the files don’t need to be in sync in real time. June 6, 2010 4:10 am Igor K Does that work both ways? June 7, 2010 9:56 am Brian Use Microsoft’s new msdeploy framework. I wrote a blog posting about how to use it with IIS6 a while back https://quickanddirtyscripting.wordpress.com/2010/03/21/msdeploy-with-iis6/ […]