MS Deploy Basics

written by Rob Aquila on Wednesday, March 25 2009

Microsoft release RC1 of its new web deployment tool called MS Deploy a few days ago and I have been playing around with it.  Here is a quick summary and reference of the basic commands to help you get started.

Command-Line Syntax

msdeploy.exe -verb:<verbName>
     -source:
<provider>[=<pathToProviderObject>
           [,
<providerSetting>=<providerSettingValue>]]
    [-dest:
<provider>[=<pathToProviderObject>
           [,
<providerSetting>=<providerSettingValue>]]
    ]
    [-
<MSDeployOperationSetting> ...]

Verbs

Verbs determine the action to completed on the source or destination object.  The most common used verbs are listed below.

  • Dump
    • Displays the information from the source object
  • Sync
    • Syncs data between source and target
  • Migrate
    • Migrates an IIS 6 web server to IIS 7
  • GetDependencies
    • List of dependencies that exist on the source machine and would need to be installed on the target machine

Providers

Providers handle specific source and destination objects.  The source and destination objects must be of the same type unless you are using the archiveDir provider to restore or create archives.  The current providers are listed below

  • appHostConfig
  • appHostSchema
  • appPoolConfig
  • archiveDir
  • auto
  • cert
  • comObject32
  • comObject64
  • contentPath
  • dbFullSql
  • dbMySql
  • gacAssembly
  • iisApp
  • machineConfig32
  • machineConfig64
  • manifest
  • metaKey
  • package
  • regKey
  • regValue
  • rootWebConfig32
  • rootWebConfig64
  • setAcl
  • webServer
  • webServer60

Examples

Scenario 1: Sync IIS Objects Between Machines

There are two providers that can be used to sync IIS objects. 

IIS 7.0

  • Web site
    • appHostConfig provider
  • Web Server
    • webServer provider

IIS 6.0

  • Web site
    • metaKey provider
  • Web Server
    • webServer60 provider

When migrating from IIS 6.0 to IIS 7.0, use the IIS 6.0 providers.

 

Web Site

Sync Web Site from IIS 7.0 to IIS 7.0

msdeploy -verb:sync -source:apphostconfig="Default Web Site",computername=sourcemachine -dest:apphostconfig="Default Web Site" -whatif > msdeploy.log

The above command will log the changes needed to sync up with the sourcemachine.  The –whatif command is used to run the command without making the actual changes. 

msdeploy -verb:dump -source:apphostconfig="Default Web Site",computername=sourcemachine

msdeploy -verb:dump -source:apphostconfig="Default Web Site",computername=sourcemachine -xml

You can also use the dump command to see the output.  Add the –xml option to output the dump as xml.  Finally, make sure the machine you are calling out to has the remote service (Web Deployment Agent Service) running. 

 

Sync Web Site from IIS 6.0 to IIS 6.0

msdeploy -verb:sync -source:metaKey=lm/w3svc/1,computername=sourcemachine -dest:metaKey=lm/w3svc/1 -whatif > msdeploy.log 

 A tool called metabase explorer can help you determine the metaKey for a site.

 

Migrate Web Site from IIS 6.0 to IIS 7.0

msdeploy -verb:migrate -source:metaKey=lm/w3svc/1,computername=sourcemachine -dest:metaKey=lm/w3svc/1 -whatif > msdeploy.log  

 

Web Server

Sync Web Server from IIS 7.0 to IIS 7.0

msdeploy -verb:sync -source:webServer,computername=sourcemachine -dest:webServer -whatif > msdeploy.log 

 

Sync Web Server from IIS 6.0 to IIS 6.0

msdeploy -verb:sync -source:webServer60,computername=sourcemachine -dest:webServer60 -whatif > msdeploy.log  

  

Migrate Web Server from IIS 6.0 to IIS 7.0

msdeploy -verb:migrate -source:webServer60,computername=sourcemachine -dest:webServer60 -whatif > msdeploy.log   

 

Scenario 2: Sync GAC Objects Between Machines

msdeploy -verb:sync -source:gacAssembly="Test.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2eds8d236nhbbf786k",computerName=sourcemachine -dest:gacAssembly -whatif > msdeploy.log

The above command will log the output of syncing the Test.Assembly GAC dll from the sourcemachine.

 

Scenario 3: Sync COM objects Between Machines

msdeploy -verb:sync -source:comObject32="Test.COM",computerName=sourcemachine -dest:combObject32 -whatif > msdeploy.log

The above command will log the output of syncing the Test.COM dll from the sourcemachine

  

Scenario 4: Sync Content Between Machines

msdeploy -verb:sync -source:contentPath=E:\Inetpub\wwwroot,computerName=sourcemachine -dest:contentPath=C:\Inetpub\wwroot -whatif > msdeploy.log

The above command will log the output of syncing files from a directory on the sourcemachine to a directory on the target machine.  The contentPath accepts the follow arguments

  • Directory path
    • C:\Inetpub
  • File path
    • C:\Inetpub\default.aspx
  • Site path
    • “Default Web Site”
  • Application path
    • “Default Web Site/App1”

 

Scenario 5: Pulling It All Together Into A Manifest

Using a manifest allows you to configure multiple providers in an xml file and executed them in the order they are listed.  Below is an example of what the manifest might look like to complete scenarios 1-3.

<site>
  
<appHostConfig path="Default Web Site" />
   <
gacAssembly path="Test.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2eds8d236nhbbf786k" />
   <
comObject32 path="Test.COM" />
</
site>

Below is the command used to execute the manifest to sync the changes from the sourcemachine to the machine it’s executed on.

msdeploy -verb:sync -source:manifest="C:\site.xml",computerName=sourcemachine -dest:manifest="C:\site.xml" -whatif > msdeploy.log 

 

Scenario 6: Replace Rule

Here is an example of replacing the path of a web site to a different path on the target machine when syncing across machines.

msdeploy -verb:sync -source:metaKey=lm/w3svc/1,computerName=sourcemachine -replace:objectName=metaproperty,match="E:\\Inetpub\\wwwroot",replace="C:\Inetput\wwwroot" -dest:metaKey=lm/w3svc/1 -whatif > msdeploy.log

Running a dump –xml will help you identify what values you need to replace.  Some more examples can be found here.

Finally, for a more detailed reference of MS Deploy go here.

Similar Posts

  1. Using VSDBCMD and MSBUILD to Build and Deploy DBPro Projects
  2. Using MS Deploy Instead of the Copy Command In MSBuild
  3. Team Foundation Server Build Notification Screen

Comments are closed

Options:

Size

Colors