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

发布于 2024-10-28 09:33:30 字数 902 浏览 1 评论 0原文

我已经能够使用 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 包来做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽容 2024-11-04 09:33:30

实际上,多亏了您的代码,我才成功将我的网站部署到云上。所以它应该有效: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);
        }

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);
        }
战皆罪 2024-11-04 09:33:30

您可以将以下行添加到代码中,

deploymentObject.SyncParameters.Load(parameters);

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

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

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>" />'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文