【问题标题】:MsBuild: 'ng' is not recognized as an internal or external commandMsBuild:“ng”未被识别为内部或外部命令
【发布时间】:2018-08-08 08:59:30
【问题描述】:

我正在尝试使用 MsBuilds 构建我的角度解决方案。

下面是我的代码sn-p

>     <Exec Command="npm install" WorkingDirectory="$(SolutionRoot)\Dev\AngularUI" />
>     <Exec Command="npm install -g @angular/cli"  WorkingDirectory="$(SolutionRoot)\Dev\AngularUI" />
>     <Exec Command="ng build --prod" WorkingDirectory="$(SolutionRoot)\Dev\AngularUI" />

虽然npm i 命令工作正常,但我在ng build --prod 命令上收到错误'ng' is not recognized as an internal or external command

我尝试从 cmd 运行相同的命令,并且在相同的构建帐户中也可以正常工作。

【问题讨论】:

  • 嗨。你喜欢这个答案吗?
  • 是的,我必须通过 Build 代理帐户在服务器上重新安装 node.js。
  • 您是在 Linux 服务器还是 Windows 上部署了这个应用程序?我有类似的问题,我不得不用间接调用 ng build 的脚本替换 ng build
  • 在 Windows 上部署它。从构建帐户重新安装 Node.js 为我修复了它

标签: angularjs node.js msbuild npm-install ng-build


【解决方案1】:

试试npm run ng build。唯一的问题是它在构建后省略了任何其他参数,例如 --prod--test

以下是我用来从 Jenkins 成功运行我的角度构建的命令。通过设置路径变量以肮脏的方式进行操作。不知道是否有更清洁的方法来做到这一点。这确实可以正确执行命令而不会省略任何内容。

set PATH=%PATH%;C:\Users\Administrator\AppData\Roaming\npm;C:\Users\Administrator\AppData\Roaming\npm\node_modules\@angular\cli\bin;

@echo on
cmd /c npm install -g @angular/cli@latest

echo yarn Install
cmd /c yarn

echo Build    
ng build --prod --aot=true

也许您也可以删除cmd /c,仍然可以。仅在出现错误时使用它以正确处理内容。

【讨论】:

    猜你喜欢
    • 2016-10-25
    • 2020-02-02
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2018-01-01
    • 1970-01-01
    相关资源
    最近更新 更多