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 RohonyanSDET, IIS Team