7

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

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

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

4

3 回答 3

6

如果您使用 MSBuild 进行 Web 部署,您可以在 .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();
}
于 2010-11-19T21:19:31.787 回答
1

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

于 2010-11-19T20:52:45.190 回答
0

你能分享你的解决方案吗?我正在使用 WebDeploy 将 asp.net webforms 应用程序部署到 IIS,我必须创建 02 个包含 .pdf 文件的虚拟目录(指向不同的驱动器)。

如何挂钩 AaronS 指向我的 .pubxml 文件的 CustomBuildTask?.Below 是文件的片段。

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>https://www.myapplication.com/app</SiteUrlToLaunchAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>www.myapplication.com</MSDeployServiceURL>
    <DeployIisAppPath>Default Web Site/app</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>administrator</UserName>
    <_SavePWD>True</_SavePWD>
    <PublishDatabaseSettings>
        <!-- ... -->
    </PublishDatabaseSettings>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)SiteConnectionString-Web.config Connection String" />
  </ItemGroup>
</Project>

从 Visual Studio 2019 发布应用程序后,IIS 应该具有 pdfmedia 虚拟目录。

pdf媒体

非常感谢你!

于 2021-04-01T20:24:53.230 回答