asp.net-core - Blazor (WASM) 和 Web Api 分离项目调试
问题描述
我在调试 Blazor Web 程序集项目时遇到问题。
设置:
- WASM Blazor UI 项目
- 引用 WASM 项目的 Web API 项目
- 它们都共享同一个端口。
- 我只启动 Web API 项目并且还可以访问 blazor 站点。(这对我来说很奇怪)
我的 Web Api 项目中有这两行。
app.UseWebAssemblyDebugging();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
启动设置 Web API:
"API": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
启动设置 Blazor WASM:
"Lab.Web": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
当我尝试在 Blazor 项目中的某处放置断点时。我收到这条消息:
“当前不会命中断点。没有为此文档加载任何符号。”
如果我单独运行 Blazor 项目,但我无法访问我的 Web API,我不会收到此消息。
在能够调试 WASM 项目的同时,为 Web API 和 Blazor WASM 共享相同端口的正确方法是什么?
ps:如果这有帮助,我正在使用 VS Studio 16.9.3。
非常感谢您的帮助!
解决方案
我假设:
- 您在 AspNetCore 而不是 IIS 中运行项目。
- 您将 API Server 项目作为您的启动项目。
- 您处于调试模式。
- 您的设置就像托管在 ASPNetCore 模板上的 Web 程序集。
您唯一需要的地方inspectUri
是 LaunchSettings.json 中的 API 项目,这是您没有的地方。
在调试模式下启动时,开始可能会很慢,所以给它时间。
推荐阅读
- excel - 如何清除 Excel 中(仅)隐藏单元格的内容(而不是删除它们)?
- cluster-analysis - 有没有办法通过相似性对多组字符串进行聚类?
- python - 确保两个数字的正差
- android - 可变参数方法的非可变参数调用
- javascript - 检查并排列两个不同的对
- tfs - TFS 2017 Rest API - 在发布获得批准后获得批准
- algorithm - 具有强度的热图算法
- express - index.html 文件未加载到我的快速服务器上
- asp.net-core - 如何使用 localhost 以外的 URL 调试 ASP.NET Core webapp
- c# - 如何抓取 Sycnfusion ScheduleView 的 VisibleDate