使用Microsoft.Web.Deployment部署Web应用程序

时间:2011-03-30 21:00:21

标签: c# deployment-project

我已经能够使用Microsoft.Web.Deployment代码将文件放在我的IIS服务器上:

DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
sourceBaseOptions.ComputerName = "localhost";

DeploymentBaseOptions destinationBaseOptions = new DeploymentBaseOptions();
destinationBaseOptions.ComputerName = ComputerName;  // remote host
destinationBaseOptions.UserName = Username;
destinationBaseOptions.Password = Password;

 DeploymentObject deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.IisApp, deployDirectory, sourceBaseOptions);

 deploymentObject.SyncTo(DeploymentWellKnownProvider.IisApp, RemoteFolderName, destinationBaseOptions, syncOptions);

似乎所有这一切都是在现有Web应用程序下创建一个新文件夹。如果我进入IIS管理器,右键单击我创建的文件夹,然后单击“转换为应用程序”,然后我得到我正在寻找的行为。有人知道如何使用Microsoft.Web.Deployment包吗?

2 个答案:

答案 0 :(得分:1)

实际上,多亏了您的代码,我设法将我的网站部署到云端。所以它应该工作:P

public static void DeployWebsite(string user, string pw, string folder, string domain, string sitename)
        {
            DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
            DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
            DeploymentBaseOptions destinationBaseOptions = new DeploymentBaseOptions();

            destinationBaseOptions.ComputerName = domain;
            destinationBaseOptions.UserName = user;
            destinationBaseOptions.Password = pw;

            DeploymentObject deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.IisApp, folder, sourceBaseOptions);
            deploymentObject.SyncTo(DeploymentWellKnownProvider.IisApp, sitename, destinationBaseOptions, syncOptions);
        }

答案 1 :(得分:1)

您可以在代码中添加以下行

deploymentObject.SyncParameters.Load(parameters);

其中parameters<project>。SetParameters.xml文件的完整路径。 在此文件中,指定虚拟应用程序名称:

<setParameter name="IIS Web Application Name" value="<WebSite>/<VirtualApp>" />'