简体   繁体   English

MsBuild:无法将“ ng”识别为内部或外部命令

[英]MsBuild: 'ng' is not recognized as an internal or external command

I am trying to build my angular solution using MsBuilds. 我正在尝试使用MsBuilds构建我的角度解决方案。

Following is my code snippet 以下是我的代码段

>     <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" />

While the npm i command works fine , i get the error 'ng' is not recognized as an internal or external command on the ng build --prod command. 尽管npm i命令可以正常工作,但在ng build --prod命令上我未将错误'ng' is not recognized as an internal or external command命令。

I try to run the same commands from cmd and it works fine from the same build account as well. 我尝试从cmd运行相同的命令,并且在相同的构建帐户中也可以正常运行。

Try npm run ng build . 尝试npm run ng build The only issue with this is it omits any other parameter like --prod or --test after build. 唯一的问题是它在构建后会忽略其他任何参数,例如--prod--test

Following are the commands what i am using to run my angular build successfully from Jenkins.Doing it the dirty way by setting up the path variables. 以下是我从詹金斯成功运行我的角度构建所使用的命令。通过设置路径变量来以肮脏的方式进行操作。 Don't know if there is a cleaner way to do this. 不知道是否有更清洁的方法来执行此操作。 This does execute the commands properly without omitting anything. 这样可以正确执行命令,而不会遗漏任何内容。

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

Probably you can remove cmd /c as well, will still work. 可能您也可以删除cmd /c ,仍然可以使用。 Using it just in case of errors to handle stuff properly. 仅在出现错误的情况下使用它才能正确处理内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM