web developer tips (46):使用Web Deployment Tool进行Web部署迁移

来源:互联网 发布:java开发必读书籍 编辑:程序博客网 时间:2024/05/21 08:53

原文地址:that Web Deployment “migrate” operation is “sync” operation with all migration rules enabled

从IIS6 迁移一个应用或整个服务器到 IIS7,需要使用“msdeploy”命令行工具来完成迁移(migrate)。
例如,你可以在服务器上建一个“migration”的包,如下:
msdeploy -verb:sync -source:webserver60 -dest:package=c:/migratedServer.zip
迁移意味着移动更多组件,然后进行同步。有关使用 Web Deployment Tool 进行部署迁移请参阅:
Migrate from IIS 6.0 to IIS 7.0

同样的在C#里可以使用web部署的公用的APIs,你可以写C#进行同步(sync),只是需要启用所有的迁移规则。c#示例代码如下:
http://www.watch-life.net/visual-studio/web-deployment-migrate-operation.html


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                );        }    }}

 

Web Deployment Tool 下载地址:
Web Deployment Tool 1.0 RC x86
Web Deployment Tool 1.0 RC x64

或者通过Web Platform Installer 下载

 

更多文章见:守望轩[http://www.watch-life.net/]

原创粉丝点击