简体   繁体   中英

Deploying a Web Application using Microsoft.Web.Deployment

I've been able to place files on my IIS server using Microsoft.Web.Deployment code:

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

It seems like all this does is create a new folder underneath an existing web application. If I go into IIS Manager, Right click the folder I created, and click "Convert to Application" then I get the behavior I was looking for. Does anyone know how to do this just using the Microsoft.Web.Deployment package?

Actually thanks to your code I managed to deploy my websites to cloud. So it should work :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);
        }

You can add the following lines to your code

deploymentObject.SyncParameters.Load(parameters);

where parameters is the full path to your <project> .SetParameters.xml file. In this file, you specify the virtual application name:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM