IIS Web 部署 - 创建虚拟目录?

发布于 2024-10-03 14:42:08 字数 223 浏览 4 评论 0原文

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

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

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

When developing a site on VS2010/IIS 7.5, I'm using Web Deploy to publish the site from my machine to the dev site server.

The site has about 40 virtual directories, and I'd like to automagically create those on the server during the deployment. Is there a simple way to do this?

I'm considering writing a small app that would load the list from a file or database and create them on demand. The directories have different physical paths on my development machine than on the web server, also, which throws a wrench into the works.

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

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

发布评论

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

评论(3

农村范ル 2024-10-10 14:42:09

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

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

<?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 虚拟目录。

pdfmedia

非常感谢!

Could you please share your solution? I'm deploying an asp.net webforms application to IIS using WebDeploy and I have to create 02 virtual directories (pointing to different drives) that hold .pdf files.

How Do I hook the CustomBuildTask that AaronS pointed on my .pubxml file? .Below is a snippet of the file.

<?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>

IIS should have the pdfmedia virtual directory after I publish the application from Visual Studio 2019.

pdfmedia

Thank you very much!

白芷 2024-10-10 14:42:08

如果您使用 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();
}

If you're using MSBuild for your web deploy you can write a CustomBuildTask in .net that you can use to create your virtual directory.

There are a lot of resources on how to create and consume a custom build task, but here is the code I use to create a virtual directory using a custom build task:

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();
}
秋凉 2024-10-10 14:42:08

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

I've not done any custom programming against WebDeploy, but I've seen reference that there is an API for it. I can't seem to find official documentation on it, but perhaps this blog+sample app could provide a start: Web Deploy API Web Application

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