问题描述
我正在测试Blazor.net,但由于WebAssembly(.net Core 3.1)缺乏调试而立即失败。
I'm testing out Blazor.net but immediately fell short on the lack of debugging in WebAssembly (.net Core 3.1).
是否有快速的&将WebAssembly应用程序重新配置为托管应用程序的简便方法,以便在开发示例时可以调试.net代码?
Is there a fast & easy way to reconfigure my WebAssembly app to a hosted app, so that I can debug the .net code as I develop my samples?
推荐答案
我刚刚看过,它展示了一个不错的技巧:
I just watched this video and it shows a nice trick:
- 向您的解决方案中添加2个项目ServerApp和WasmApp。
- 在ServerApp中,添加对WasmApp的引用
-
在ServerApp._Host.cshtml中,将此行更改为使用
WasmApp.App
:
< component type = typeof(WasmApp.App)呈现模式= ServerPrerendered />
现在从ServerApp项目中删除所有.razor文件和生成的无效代码。
now remove all .razor files and the resulting dead code from the ServerApp project.
您现在可以在WasmApp中开发所有页面,也可以在ServerApp中运行它们。唯一的重复是在添加css或js文件时并行维护 _Host.cshtml
和 index.html
。
You can now develop all blazor pages in the WasmApp and also run them with the ServerApp. The only duplication is in maintaining _Host.cshtml
and index.html
in parallel when you add css or js files.
并且vid als显示了一个附加功能来显示正在运行的内容:
And the vid als showed an additional feature to show what is running:
@using System.Runtime.InteropServices
<p>Env: @Environment</p>
@code{
string Environment = RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY"))
? "WebAssembly"
: "Server";
}
将此内容放在您的主页或NavMenu上。
put this on you main page or NavMenu or something.
这篇关于将WebAssembly Blazor转换为托管的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!