用PowerShell命令一次启动多个前后端应用
前言
最近再做一个POC,有两个后端API和一个前端,每次运行好麻烦,然后就写了个ps1文件,点击执行。
正文
直接上代码吧,大家可以参考
<# 同时启动两个NetCore后端 + React前端,所有日志在同一个窗口 #> # 项目路径配置,根据你本地路径修改 $api1Path = "C:\Source Code\SmartFlow\SmartFlow.API" $api2Path = "C:\Source Code\SmartFlow\SmartFlow.AI" $reactPath = "C:\Source Code\SmartFlow\SmartFlow.Web" Write-Host "===== Start the solution =====" -ForegroundColor Cyan # 定义并行任务 $jobs = @() # 任务1:API1 $jobs += Start-Job -ScriptBlock { Set-Location $using:api1Path dotnet watch run } -Name "Api1" # 任务2:API2 $jobs += Start-Job -ScriptBlock { Set-Location $using:api2Path dotnet watch run } -Name "Api2" # 任务3:React前端 $jobs += Start-Job -ScriptBlock { Set-Location $using:reactPath npm run dev } -Name "React" Write-Host "All Services have been started (Ctrl+C Stop All Services)" -ForegroundColor Green # 持续输出所有Job日志到当前窗口 try { while ($true) { foreach ($job in $jobs) { Receive-Job -Job $job } Start-Sleep -Milliseconds 300 } } finally { Write-Host "Stopping All Services..." -ForegroundColor Yellow Get-Job | Remove-Job -Force }
然后,又写了一个bat命令,点击启动上面的ps1
@echo off powershell -ExecutionPolicy Bypass -File "%~dp0start.ps1"
结束语
能偷懒的时候,一定要学会偷懒,hhhh
| 博文推荐: |
| SharePoint 2013 WebPart 管理工具分享[开源] |
| 基于SharePoint 2013的论坛解决方案[开源] |
| SharePoint 2013 学习基础系列入门教程 |
| SharePoint 2013 图文开发系列之门教程 |
| SharePoint Designer 学习系列入门教程 |
| 特:如果有Power Platform、Azure、Microsoft 365、SharePoint项目,欢迎邮件联系我,Email:linyu_s@163.com |

浙公网安备 33010602011771号