You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PowerShell构建多Angular应用异常:仅完成首个应用构建

问题根源

你第一个ng build命令里的--watch参数是核心问题——这个参数会让Angular CLI持续监听项目文件变化,一旦有修改就自动重新构建,该命令会一直处于运行状态,不会主动退出。PowerShell脚本是按顺序执行命令的,前一个命令没结束,后面的代码就永远不会被触发,所以脚本停在了第一个构建步骤,根本没走到"3"那行。

解决方案

根据你的实际需求,有两种处理方式:

方式一:仅一次性构建(无需实时监听)

直接去掉所有ng build命令中的--watch参数,这样每个构建命令完成后会自动退出,脚本会继续执行下一个步骤。修改后的脚本如下:

"1" ;
cd D:\GitNew\App\src\Applications\FT.SomeProject.Web ;

"2" ;
ng build --output-hashing=all --project=app --deploy-url /dist/app/ --output-path wwwroot/dist/app/ ;

"3" ;
ng build --output-hashing=all --project=admin --deploy-url /dist/admin/ --output-path wwwroot/dist/admin/ ;

"4" ;
ng build --output-hashing=all --project=teams --deploy-url /dist/teams/ --output-path wwwroot/dist/teams/ ;

"done" ;
cmd /k ;

方式二:需要同时监听多个项目的文件变化

如果确实要保持实时监听,得让每个ng build在后台独立进程中运行,这样PowerShell不用等待前一个命令结束就能继续执行后续代码。可以用PowerShell的Start-Process命令,示例如下:

"1" ;
cd D:\GitNew\App\src\Applications\FT.SomeProject.Web ;

"2" ;
Start-Process ng -ArgumentList "build --output-hashing=all --project=app --watch --deploy-url /dist/app/ --output-path wwwroot/dist/app/" -NoNewWindow ;

"3" ;
Start-Process ng -ArgumentList "build --output-hashing=all --project=admin --watch --deploy-url /dist/admin/ --output-path wwwroot/dist/admin/" -NoNewWindow ;

"4" ;
Start-Process ng -ArgumentList "build --output-hashing=all --project=teams --watch --deploy-url /dist/teams/ --output-path wwwroot/dist/teams/" -NoNewWindow ;

"done" ;
cmd /k ;

注:-NoNewWindow参数会让所有构建日志输出到当前窗口,若想每个项目单独开窗口查看日志,去掉这个参数即可。

内容的提问来源于stack exchange,提问作者imsuktoday

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 06:42:47