Tip #46: Did you know… that Web Deployment “migrate” operation is “sync” operation with all migration rules enabled?

Note: C# code in this article applies to RC version of Web Deployment Tool available here:
Web Deployment Tool 1.0 RC x86
Web Deployment Tool 1.0 RC x64
or through WebPI tool:
Web Platform Installer

To migrate an application or whole server from IIS6 to IIS7 you need to use “migrate” verb in msdeploy command line tool.
For example, you can create a “migration” package of a server in the following manner:

msdeploy -verb:sync  -source:webserver60 -dest:package=c:\migratedServer.zip

Migration is meant to pull out more components then sync operation. To read more about migration using Web Deployment Tool refer to this article: Migrate from IIS 6.0 to IIS 7.0

To do the same in C# using Web Deployment public APIs, you write the same code as you would write for sync except that you have to enable all the migration rules.

(Note: for remote settings explore properties of DeploymentBaseOptions and for sync specific settings like skip rules and other options, explore properties of DeploymentSyncOptions).

using System;
using Microsoft.Web.Deployment;

static class Program
    static void Main()
        DeploymentWellKnownProvider sourceProvider = DeploymentWellKnownProvider.WebServer60;
        string sourcePath = "";     // no path needed for webserver providers
        DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
         * set base options for source object (webserver)

        DeploymentWellKnownProvider destinationProvider = DeploymentWellKnownProvider.Package;
        string destinationPath = @"c:\migratedServer.zip";
        DeploymentBaseOptions destinationBaseOptions = new DeploymentBaseOptions();
        DeploymentSyncOptions destinationSyncOptions = new DeploymentSyncOptions();

        // add all migration rules to sync options
        DeploymentRuleCollection availableRules = DeploymentSyncOptions.GetAvailableRules();
        foreach (DeploymentRule rule in availableRules)
            if (rule.Name.Equals("MigrateGeneral") || 
rule.Name.Equals("MigrateDependencyCheck") ||
rule.Name.Equals("MigrateAnonymousUser")) { destinationSyncOptions.Rules.Add(rule); } } /* * set other base and sync options for destination object (package) */ using (DeploymentObject deploymentObject = DeploymentManager.CreateObject ( sourceProvider, sourcePath, sourceBaseOptions )) { deploymentObject.SyncTo ( destinationProvider, destinationPath, destinationBaseOptions, destinationSyncOptions ); } }
Kateryna Rohonyan


Comments (4)

  1. Thank you for submitting this cool story – Trackback from DotNetShoutout

  2. What's New says:

    Note: C# code in this article applies to RC version of Web Deployment Tool available here: – Web Deployment

  3. My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. Sorry about the long pause between posts. That work thing just got in the way too much. Miguel de Icaza announced that Mono 2.4 and