简体   繁体   English

将 WebAssembly Blazor 转换为托管的

[英]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:我刚刚看了这个视频,它展示了一个很好的技巧:

  • Add 2 projects to your solution, ServerApp and WasmApp.将 2 个项目添加到您的解决方案中,ServerApp 和 WasmApp。
  • in your ServerApp, add a reference to WasmApp在您的 ServerApp 中,添加对 WasmApp 的引用
  • 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.cshtmlindex.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.

相关问题 Blazor webassembly 托管在子文件夹中 - Blazor webassembly hosted in sub folder blazor webassembly windows 身份验证 + .netcore 托管 - blazor webassembly windows authentication + .netcore hosted 使用数据库资源本地化 Blazor 托管的 Web 程序集 - Localize a Blazor hosted Webassembly with a databse resource 请求 header 'Referer' 在托管 Blazor Webassembly 和非托管 Blazor Webassembly 之间是不同的 - Request header 'Referer' is different between Hosted Blazor Webassembly, and non hosted Blazor Webassembly 部署托管到 Azure 的 Blazor WebAssembly 应用 ASP.NET Core - Deploy Blazor WebAssembly App ASP.NET Core hosted to Azure 如何使用 ASP.NET 核心托管发布 Blazor WebAssembly - How to publish Blazor WebAssembly with ASP.NET Core hosted 没有托管的 Blazor WebAssembly 作为客户端与 .Net Core WebAPI 作为服务器端交互 - Blazor WebAssembly without hosted act as client side interact with .Net Core WebAPI as server side 如何在具有控制器 API 服务的 razor pages 应用程序托管的 blazor webassembly 上启用 CORS - How to enable CORS on a blazor webassembly, hosted by a razor pages app with controller API services Blazor Webassembly (PWA) 是否支持独立的 session 存储(不在 asp.net 内核中托管)? - Is session storage supported in Blazor Webassembly (PWA) standalone (Not hosted in asp.net core)? C# .NET 核心托管 Blazor WebAssembly - 将其他客户端添加到.Server 项目 ZDB974238714CA38DE634A7CE1D0 - C# .NET Core Hosted Blazor WebAssembly - Add additional clients to .Server project API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM