Azure:如何从 Visual Studio 项目部署子目录?

标签 azure visual-studio-2015 azure-web-app-service msdeploy webdeploy

我已经为此苦苦挣扎了一段时间,我觉得我一定错过了一些明显的东西......

我们正在使用 Visual Studio 2015、Typescript、Angular、bower、grunt 等编写一个 Web 应用程序。该项目将所有 HTML、SASS 和 Typescript 文件构建到一个目录 www 中,可供使用部署到网络服务器。

生成的项目结构如下所示(括号中生成/复制的文件):

OurProject/
   bower_components/
   node_modules/
   typings/
   source/
      index.html
      ...lots of .ts, .sass and .html files
   www/
      js/
         (...javascript libraries...)
      (index.html)
      (app.min.js)
      (app.min.css)

当我们将此项目部署到 Azure 网站时,我希望看到以下结构:

OurProject.azurewebsites.net/
   js/
      ...various libraries...
   index.html
   app.min.js
   app.min.css

但是我们实际上得到的是这个 - 即整个项目树,包括源代码、构建工具等:

OurProject.azurewebsites.net/
   bower_components/
   node_modules/
   typings/
   source/
      index.html
      ...lots of .ts, .sass and .html files
   www/
      (index.html)
      (app.min.js)
      (app.min.css)

这有缺点

  • 发布我们的源代码
  • 向 Azure 发送垃圾邮件(node_modules 巨大)
  • 拥有登陆页面whiz.bang.com/www(而不仅仅是whiz.bang.com)

必须有一种方法告诉 Visual Studio 2015 发布引擎“仅发布 www 子目录” - 但谁能告诉我怎么做?

到目前为止尝试过:

我尝试按照 Sayed Hashimis blog 上的食谱进行操作,描述如何在部署中包含和排除选定的文件和目录。

除了需要手动编辑未记录的 pubxml 功能之外,这仍然无法解决“尴尬的着陆页”问题。

每当您向项目添加新目录时,您都必须更新排除列表。

另一次尝试:

一种解决方案是添加引用 OurProject/www/目录的网站项目(“添加现有网站...”):

OurSolution/
   OurProject/
      bower_components/
      node_modules/
      typings/
      source/
         index.html
         ...lots of .ts, .sass and .html files
      www/
         js/
            ...various libraries...
         (index.html)
         (app.min.js)
         (app.min.css)
   WebSiteProject (references existing web site ..\OurProject\www)/
      js/
         ...various libraries...
      index.html
      app.min.js
      app.min.css

然后可以将该项目 (WebSiteProject) 部署到 Azure,从而产生所需的结果。

但这似乎是实现简单目标的一种非常迂回的方式......

最佳答案

根据您的要求,我做了一些测试。 我可以将 subdir 中的内容部署到 Azure Web App 的根目录中,请按照以下步骤操作:

  1. 创建一个与您提到的项目结构相同的 MVC 网站 enter image description here

  2. 编辑您的发布配置文件,在部署到 Azure 之前添加一些 MSBuild 任务。您可以使用RemoveDir、Move 任务定义一个目标,这些任务在CopyAllFilesToSingleFolderForMsdeploy 之后执行,并将其放在发布配置文件中的PropertyGroup 之后。 以下是详细代码,您可以复制并粘贴到您的发布配置文件中。

<Target Name="DeploySubFolder" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
  <!--1.Deleting Folders except www-->
  <ItemGroup>
    <_FolderToDelete Include="$(_PackageTempDir)\bower_components" />
    <_FolderToDelete Include="$(_PackageTempDir)\node_modules" />
    <_FolderToDelete Include="$(_PackageTempDir)\source" />
    <_FolderToDelete Include="$(_PackageTempDir)\typings" />
  </ItemGroup>
  <RemoveDir Directories="@(_FolderToDelete)" />

  <!--2.Copying files,folders from www to root directory-->
  <ItemGroup>
    <_FileToMove Include="$(_PackageTempDir)\www\**" />
  </ItemGroup>
  <Move SourceFiles="%(_FileToMove.Identity)" DestinationFolder="$(_PackageTempDir)\%(RecursiveDir)" />

  <!--3.Deleting the empty folder www-->
  <RemoveDir Directories="$(_PackageTempDir)\www" />
</Target>
  • 使用修改后的发布配置文件将 Web 应用程序部署到 Azure。

  • 通过 KUDU 检查 Azure Web App 中 Web 应用程序的结构

  • enter image description here

    关于Azure:如何从 Visual Studio 项目部署子目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39011007/

    相关文章:

    VS 2015中没有出现Mysql数据库选项

    c# - 数十次调用后应用程序服务 502 网关错误

    winforms - 利用 Windows Azure 进行 ClickOnce 发布

    JSON 可选字段而不是必填字段

    windows - 在 Windows Azure 辅助角色和 Web 角色中使用 SignalR

    entity-framework - 解决 Microsoft.Data.Entity.SqlServer 的依赖关系失败

    visual-studio - Angular 2 beta 13 with Visual Studio 2015 update 2/编译保存

    Azure 存储队列客户端不会将消息放入有害队列中

    c# - azure web 应用程序中的 HttpContext 中的用户配置文件为空

    java - Azure WebApp - Tomcat 关闭