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

如何在Visual Studio中同时启动Clean Architecture的Blazor WASM客户端与服务端项目

在Visual Studio中同时启动Blazor WASM客户端与服务端项目的方法

我正在基于.NET Core开发Blazor WebAssembly解决方案,采用Clean Architecture架构,客户端与服务端为独立项目。为提升开发调试效率,需要找到在Visual Studio中同时启动两者的方法。当前我通过DemoBWasm.Launcher项目使用dotnet watch --project xxx命令运行两个项目,后续计划将服务端与客户端部署在不同系统。

解决方案结构如下:

└───DemoBWasm
    └───src
        ├───DemoBWasm.Launcher
        ├───Client
        │   └───DemoBWasm.Client
        │       ├───Pages
        │       ├───Properties
        │       ├───Shared
        │       └───wwwroot
        │           ├───css
        │           │   ├───bootstrap
        │           │   └───open-iconic
        │           │       └───font
        │           │           ├───css
        │           │           └───fonts
        │           └───sample-data
        ├───Server
        │   ├───DemoBWasm.Application
        │   ├───DemoBWasm.Domain
        │   ├───DemoBWasm.Infrastructure
        │   └───DemoBWasm.Server
        │       ├───Controllers
        │       └───Properties
        ├───Shared
        │   └───DemoBWasm.Shared
        └───Test
            ├───Client
            │   └───DemoBWasm.Client.Test
            └───Server
                └───DemoBWasm.Server.Test

以下是几种可行的实现方式:

方法一:设置多个启动项目

  • 右键解决方案,选择「属性」
  • 在「启动项目」选项卡中,选择「多个启动项目」
  • 分别将DemoBWasm.Client和DemoBWasm.Server的「操作」设置为「启动」
  • 点击「确定」后,按下F5即可同时启动两个项目,各自打开对应的调试窗口

方法二:自定义启动配置文件

可以在项目的launchSettings.json中添加多项目启动配置,步骤如下:

  1. 打开服务端项目(DemoBWasm.Server)的Properties/launchSettings.json
  2. 添加以下配置节点:
"Multi-Launch": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "https://localhost:5001",
  "projects": ["../Client/DemoBWasm.Client/DemoBWasm.Client.csproj", "DemoBWasm.Server.csproj"],
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}
  1. 在Visual Studio的启动配置下拉框中选择「Multi-Launch」,点击启动即可同时运行两个项目

方法三:优化现有Launcher项目

如果希望保留现有的Launcher项目,可以通过修改项目文件实现一键启动:

  1. 打开DemoBWasm.Launcher的.csproj文件
  2. 添加以下目标配置:
<Target Name="StartProjects" AfterTargets="Build">
  <Exec Command="start dotnet watch run --project ../Client/DemoBWasm.Client/DemoBWasm.Client.csproj" />
  <Exec Command="start dotnet watch run --project ../Server/DemoBWasm.Server/DemoBWasm.Server.csproj" />
</Target>
  1. 将Launcher项目设置为启动项目,运行后会自动打开两个终端分别启动客户端和服务端,同时支持热重载

以上三种方法均不影响后续的独立部署需求,仅用于开发阶段提升调试效率。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 12:44:56