使用新的 VSO 构建代理为 vNext 应用程序设置 CD

Setting up CD for vNext app with new VSO build agent

我正在尝试使用新的 Visual Studio 在线构建代理为我的 vNext 应用程序设置持续部署。

请注意:我已经从源代码管理中排除了 /wwwroot 文件夹。 “默认”Grunt 处理所有 CSS + JS 连接 + 缩小并将其放入文件夹中。我已经为此任务设置了预构建绑定,因此您只需右键单击并发布该应用程序即可。这很好用,因为发布将进行构建——这会触发 Grunt 任务来准备分发。

但是 - VSO 构建代理似乎不会触发 Grunt 任务。因此构建服务器没有任何 /wwwroot 内容,因此部署不起作用。

我该如何解决这个问题?或者 - 我应该只在源代码管理中包含 /wwwroot 文件夹吗?

经过一整天的思考 - 我找到了解决方案。但是,我担心这只是一个临时解决方案。一旦发布新的 VSO 构建任务,这将变得容易得多。

这是我所做的:

  1. 我首先安装了最新版本的 Node onto the build server, which seemed to speed things up and got rid of some strange warnings. Also - I updated to the latest version of the build agent ( see bottom of this page how)。检查 Node 是否在路径中并全局安装 bower 和 grunt(npm install -g bowernpm install -g grunt-cli

  2. 然后我在 Visual Studio 在线从头开始使用新的构建模板,正确设置 Git 绑定并添加第一步:NPM 安装(添加一个步骤 - select 'NPM Install')。将工作目录设置为 .xproj

  3. 的文件夹
  4. 下一步:添加 'Grunt build' 步骤。将它指向您的 Gruntfile.js + 将工作目录设置为同一目录。我是 运行 grunt task build 因为它带有 yeoman 模板。我进行了修改,因此它将所有内容输出到 /wwwroot 文件夹中。

  5. 添加构建项目位的 'Visual Studio Build' 步骤。添加参数 /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=\"$(build.stagingDirectory)\"

所以,这就是全部 'out-of-the-box'。接下来的步骤(打包应用程序 + 部署它)不是。我怀疑将来我们会有很好的 VSO 构建任务,这将使这很容易做到。我不得不 fiddle 使用命令行。 但是,事实证明我很容易。如果您从 Visual Studio 设置发布 - 您可以在输出 window 中看到它运行的命令。您想在 2 个命令步骤中重新创建这些命令。

  1. 为命令 C:\Users\Administrator\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta6\bin\dnu.cmd 添加命令行步骤。是的——它现在耦合到 DNX 运行时——所以这不是最优的。但是我们需要 DNX Utility 来打包我们的应用程序——因此命令参数: publish --out $(build.stagingDirectory) --configuration Release --wwwroot-out "wwwroot" --runtime dnx-clr-win-x86.1.0.0-beta6(再次 - 只是从 VS 的输出 window 复制它)

这会很好地将应用程序打包到 $(build.stagingDirectory) 文件夹中。 下一步 - 在云端获取它。

  1. 使用命令添加最后的 'command line' 步骤:C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe 和参数 -source:IisApp='$(build.stagingDirectory)\wwwroot' -dest:IisApp='--something--',ComputerName='https://--something--.scm.azurewebsites.net/msdeploy.axd',UserName='$--something--',Password='--notsaying--',IncludeAcls='False',AuthType='Basic' -verb:sync -enableLink:contentLibExtension -retryAttempts:2

注意:这假定您已设置发布到网站。转到 Azure 门户 - 到您的 Azure 网站 - 并设置发布。下载发布配置文件 XML 文件,您会在其中找到这些参数。此外 - 所有参数都写入 Visual Studio 输出 window(密码除外)。

这现在对我有用:使用新的 Visual Studio 在线 (VSO) 构建代理连续部署 vNext / ASP.NET 5 网络应用程序。