在 VS2010/IIS 7.5 上开发站点时,我使用 Web Deploy 将站点从我的计算机发布到开发站点服务器。

该站点有大约 40 个虚拟目录,我想在部署期间在服务器上自动创建这些目录。有没有一种简单的方法可以做到这一点?

我正在考虑编写一个小型应用程序,它可以从文件或数据库加载列表并根据需要创建它们。这些目录在我的开发计算机上与 Web 服务器上具有不同的物理路径,这也给工作带来了麻烦。

有帮助吗?

解决方案

如果您正在使用的MSBuild为您的网络部署可以在.NET编写CustomBuildTask,你可以用它来创建虚拟目录。

有关于如何创建大量的资源消耗和一个自定义生成任务,但这里是我使用使用自定义生成任务,以创建一个虚拟目录的代码:

public void CreateVirtualDirectory()
{

    DirectoryEntry oDE = new DirectoryEntry("IIS://" +
            this._strServerName + "/W3SVC/" + _webSiteID + "/Root");


    //Get Default Web Site
    DirectoryEntries oDC = oDE.Children;

    //Add row to schema
    DirectoryEntry oVirDir = oDC.Add(this._strVDirName,
                oDE.SchemaClassName.ToString());

    //Commit changes for Schema class File
    oVirDir.CommitChanges();


    //Set virtual directory to physical path
    oVirDir.Properties["Path"].Value = this._strPhysicalPath;

    //Set read access
    oVirDir.Properties["AccessRead"][0] = true;

    //Set the default docs
    oVirDir.Properties["EnableDefaultDoc"][0] = true;
    oVirDir.Properties["DefaultDoc"][0] = "default.aspx";

    //set the name
    oVirDir.Properties["AppFriendlyName"][0] = this._strVDirName;

    //do it
    oVirDir.Invoke("AppCreate", true);


    //set the application pool
    if (!string.IsNullOrEmpty(_strApplicationPool))
    {
        object[] param = { 0, _strApplicationPool, true };
        oVirDir.Invoke("AppCreate3", param);
        oVirDir.Properties["AppIsolated"][0] = "2";
    }

    //Save all the changes
    oVirDir.CommitChanges();
}

其他提示

我还没有针对 WebDeploy 进行任何自定义编程,但我已经看到有一个针对它的 API 的参考资料。我似乎找不到关于它的官方文档,但也许这个博客+示例应用程序可以提供一个开始: Web 部署 API Web 应用程序

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top