Angular CLI VSO 持续集成 [英] Angular CLI VSO Continuous Integration

查看:27
本文介绍了Angular CLI VSO 持续集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去曾为使用 npm 命令的 Angular2 项目设置 CI,但我最近开始使用使用ng"命令的 Angular-CLI.

当我尝试在 Visual Studio Online 中为我的项目设置 CI 时,我找不到执行ng"命令的方法.

我尝试运行 NPM 命令(使用目录中的 npm 任务)来安装 CLI;npm install -g angular-cli,然后我运行 npm install.现在要运行ng build",我尝试使用命令行工具运行(因为似乎没有允许我运行 ng 命令的工具),但是未能说明 ng 不是可识别的命令.

对于使用 VSO 为 Angular-CLI 项目设置 CI 有什么建议吗?

谢谢

解决方案

如果您希望您的构建定义在任何构建代理(托管代理和任何本地代理)上运行,您可以依赖 的本地安装angular-cli 带有 npm没有 -g 标志:

>npm install angular-cli

默认情况下,npm 会在 .\node_modules\.bin\

下安装 'ng'

您的构建定义可以使用

  • 创建项目helloworldproject":

  • 构建项目helloworldproject":

==更新(使用npm bin"以编程方式检索实际二进制路径)==

要消除放置二进制文件的假设并具有更具弹性的构建定义,您可以使用以下命令以编程方式检索 npm 使用的实际二进制路径:

>npm bin

以下示例(这次是一个简短的 PowerShell 脚本)展示了如何创建helloworldproject"并在此之后构建它:

记住:

  • 禁用 PowerShell 任务上的标准错误失败"选项,因为 ng 工具即使成功也喜欢在那里写东西.
  • 当然,在使用 'ng' 工具之前,您仍然需要 'npm install' 任务,如上所示.

I have set up CI for Angular2 projects in the past which use npm commands, however I recently started using Angular-CLI which uses 'ng' commands instead.

When I try to set up CI for my project in Visual Studio Online I can't find a way to execute 'ng' commands.

I have tried running NPM command (using npm task from the catalog) to install the CLI; npm install -g angular-cli, after that I run npm install. Now to run 'ng build' I have tried to run in using command line tool (since there doesn't appear to be a tool to allow me to run ng commands), however that fails saying that ng is not a recognised command.

Any suggestions on setting up CI for an Angular-CLI project using VSO?

Thanks

解决方案

If you want your build definition to run on any build agent (the Hosted one and any on premise agent), you could relying on local installation of angular-cli with npm, without the -g flag:

>npm install angular-cli

By default npm will install 'ng' under .\node_modules\.bin\

Your build definition could use the 'npm install' task to install locally 'ng', then you can invoke it by 'Command Line' task because you know the path to it (e.g. $(Build.SourcesDirectory)\node_modules\.bin).

Example of a build definition creating a new project and building it using 'ng':

  • install locally the 'ng' cli tool:

  • create the project 'helloworldproject':

  • build the project 'helloworldproject':

==Update (programmatically retrieve the actual binary path with 'npm bin')==

To remove the assumption where the binaries are placed and have a more resilient build definition, you could retrieve programmatically the actual binary path used by npm using the command:

>npm bin

The following example (this time a short PowerShell script) shows how to create the 'helloworldproject' and build it thereafter:

Remember:

  • to disable the option 'Fail on Standard Error' on the PowerShell task, as the ng tools likes to write stuff there even when it succeeds.
  • of course you still need the 'npm install' task as shown above before using the 'ng' tool.

这篇关于Angular CLI VSO 持续集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆