[英]Convert WebAssembly Blazor to a Hosted one
I'm testing out Blazor.net but immediately fell short on the lack of debugging in WebAssembly (.net Core 3.1).我正在测试 Blazor.net,但由于 WebAssembly (.net Core 3.1) 中缺乏调试而立即失败。
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?是否有一种快速简便的方法可以将我的 WebAssembly 应用程序重新配置为托管应用程序,以便我可以在开发示例时调试 .net 代码?
I just watched this video and it shows a nice trick:我刚刚看了这个视频,它展示了一个很好的技巧:
in ServerApp._Host.cshtml , change this line to use WasmApp.App
:在 ServerApp._Host.cshtml 中,将此行更改为使用
WasmApp.App
:
<component type="typeof(WasmApp.App)" render-mode="ServerPrerendered" />
now remove all .razor files and the resulting dead code from the ServerApp project.现在从 ServerApp 项目中删除所有 .razor 文件和由此产生的死代码。
You can now develop all blazor pages in the WasmApp and also run them with the ServerApp.您现在可以在 WasmApp 中开发所有 blazor 页面,也可以使用 ServerApp 运行它们。 The only duplication is in maintaining
_Host.cshtml
and index.html
in parallel when you add css or js files.唯一的重复是在添加 css 或 js 文件时并行维护
_Host.cshtml
和index.html
。
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("BROWSER")) // was "WEBASSEMBLY"
? "WebAssembly"
: "Server";
}
put this on you main page or NavMenu or something.把它放在你的主页或 NavMenu 或其他东西上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.