如何配置VS Code调试器,在dotnet watch run时调试.Net Core内嵌Angular应用
.NET API与Angular联动调试配置问题
项目结构
APIProject ↓AngularApp ↓.vscode launch.json tasks.json package.json Startup.cs
需求说明
执行dotnet watch run启动APIProject时,希望自动启动AngularApp并启用其调试器。目前AngularApp可通过ng serve直接启动调试,但尝试在Startup.cs的Configure方法中调用launch.json内的npm脚本未成功。
当前配置文件
Startup.cs
public void ConfigureServices(IServiceCollection services) { // (无关代码已省略) services.AddSpaStaticFiles(configuration => { configuration.RootPath = "AngularApp/dist"; }); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // (无关代码已省略) app.UseSpa(spa => { spa.Options.SourcePath = "AngularApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); }
AngularApp/package.json(已省略无关部分)
{ "name": "AngularApp", "version": "0.0.0", "scripts": { "ng": "ng", "start-debug": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve", "start": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve", "build": "ng build", "build:ssr": "ng run AngularApp:server:dev", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "postinstall": "ngcc", "ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build" } }
AngularApp/.vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "name": "debug-angular-serve", "type": "msedge", "request": "launch", "preLaunchTask": "npm: start-debug", "url": "http://localhost:4200", "webRoot": "${workspaceFolder}" }] }
AngularApp/.vscode/tasks.json
{ "version": "2.0.0", "tasks": [ { "type": "npm", "script": "start-debug", "isBackground": true, "presentation": { "focus": true, "panel": "dedicated" }, "group": { "kind": "build", "isDefault": true }, "problemMatcher": { "owner": "typescript", "source": "ts", "applyTo": "closedDocuments", "fileLocation": [ "relative", "${cwd}" ], "pattern": "$tsc", "background": { "activeOnStart": true, "beginsPattern": { "regexp": "(.*?)" }, "endsPattern": { "regexp": "Compiled |Failed to compile." } } } }, ] }
内容的提问来源于stack exchange,提问作者Numan
相关产品推荐
相关产品推荐

