如何在 VS Code 中同时运行多个 ASP.NET Core 项目?

问题描述 投票:0回答:1

我有两种类型的 .NET 项目,第一种是 ASP.NET Core Web API(用于后端),第二种是 Blazor WASM(用于前端)。

是否可以在 VS Code 中使用 dotnet cli 将这两个项目配置为同时运行?

在示例视频中,讲师仅使用 Visual Studio 2022。我没有 Visual Studio 2022,因为它占用大量内存并且在我的计算机上运行速度非常慢,所以我很早就删除了它。

visual-studio-code asp.net-core-webapi blazor-webassembly
1个回答
0
投票

我在这里开始了一个工作示例。

1.项目结构

enter image description here

2.tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "msbuild",
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            
        },
        {
            "label": "buildbackend",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Backend/Backend.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "buildfrontend",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Frontend/Frontend.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

3.launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
        "name": ".NET Core Launch (Frontend)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "buildfrontend",
        "program": "${workspaceFolder}/Frontend/bin/Debug/net8.0/Frontend.dll",
        "args": [],
        "cwd": "${workspaceFolder}/Frontend",
        "stopAtEntry": false,
        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
        },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "sourceFileMap": {
            "/Views": "${workspaceFolder}/Views"
        }
        },
        {
        "name": ".NET Core Launch (Backend)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "buildbackend",
        "program": "${workspaceFolder}/Backend/bin/Debug/net8.0/Backend.dll",
        "args": [],
        "cwd": "${workspaceFolder}/Backend",
        "stopAtEntry": false,
        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
        },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "sourceFileMap": {
            "/Views": "${workspaceFolder}/Views"
        }
        }
    ],
    "compounds": [
        {
          "name": "Frontend & Backend",
          "configurations": [
            ".NET Core Launch (Frontend)",
            ".NET Core Launch (Backend)"
          ],
          "stopAll": true
        }
      ]
}

注意:launchch中

preLaunchTask
的值需要与tasks
中定义的
label

相同

4.调试选择

enter image description here

多重注视

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.