简体   繁体   English

已发布托管 Blazor wasm 应用程序仅显示正在加载

[英]Published hosted Blazor wasm app only shows Loading

I would like to publish a hosted Blazor WASM application and run the generated.exe locally for test purposes.我想发布一个托管的 Blazor WASM 应用程序并在本地运行 generate.exe 以进行测试。 To do this with the standard blazorwasm template I have tried the following steps:要使用标准 blazorwasm 模板执行此操作,我尝试了以下步骤:

dotnet new blazorwasm --hosted
dotnet publish -c Release

Then I have started the generated server.exe file.然后我启动了生成的 server.exe 文件。 When I now open http://localhost:5001 in the browser it just displays "Loading...", but never loads the blazor application.当我现在在浏览器中打开 http://localhost:5001 时,它只显示“正在加载...”,但从不加载 blazor 应用程序。 There is also no console output from the server.服务器也没有控制台 output。 Did I misunderstand how this is supposed to work?我是否误解了这应该如何工作?

Run the 'dotnet publish -c Release' on the /Server folder.在 /Server 文件夹上运行“dotnet publish -c Release”。

Running it at the solution level does not produce the wasm files in the publish folder, or they are somehow cleared out...在解决方案级别运行它不会在发布文件夹中生成 wasm 文件,或者它们以某种方式被清除......

Solution Publish解决方案发布

PS C:\Users\u0\Desktop\Blazor> dotnet publish -c Release
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Blazor.Shared -> C:\Users\u0\Desktop\Blazor\Shared\bin\Release\net5.0\Blazor.Shared.dll
  Blazor.Shared -> C:\Users\u0\Desktop\Blazor\Shared\bin\Release\net5.0\publish\
  Blazor.Client -> C:\Users\u0\Desktop\Blazor\Client\bin\Release\net5.0\Blazor.Client.dll
  Blazor.Client (Blazor output) -> C:\Users\u0\Desktop\Blazor\Client\bin\Release\net5.0\wwwroot
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Compressing Blazor WebAssembly publish artifacts. This may take a while...
  Blazor.Client -> C:\Users\u0\Desktop\Blazor\Client\bin\Release\net5.0\publish\
  Blazor.Server -> C:\Users\u0\Desktop\Blazor\Server\bin\Release\net5.0\Blazor.Server.dll
  Blazor.Server -> C:\Users\u0\Desktop\Blazor\Server\bin\Release\net5.0\Blazor.Server.Views.dll
  Blazor.Server -> C:\Users\u0\Desktop\Blazor\Server\bin\Release\net5.0\publish\

Server Project Publish服务器项目发布

PS C:\Users\u0\Desktop\Blazor\Server> dotnet publish -c Release
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Blazor.Shared -> C:\Users\u0\Desktop\Blazor\Shared\bin\Release\net5.0\Blazor.Shared.dll
  Blazor.Client -> C:\Users\u0\Desktop\Blazor\Client\bin\Release\net5.0\Blazor.Client.dll
  Blazor.Client (Blazor output) -> C:\Users\u0\Desktop\Blazor\Client\bin\Release\net5.0\wwwroot
  Blazor.Server -> C:\Users\u0\Desktop\Blazor\Server\bin\Release\net5.0\Blazor.Server.dll
  Blazor.Server -> C:\Users\u0\Desktop\Blazor\Server\bin\Release\net5.0\Blazor.Server.Views.dll
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Compressing Blazor WebAssembly publish artifacts. This may take a while...
  Blazor.Server -> C:\Users\u0\Desktop\Blazor\Server\bin\Release\net5.0\publish\

Try to use F12 developer tools to check the website, you can see that, the framework/blazor.webassembly.js doesn't load successfully:尝试使用F12开发者工具查看网站,可以看到framework/blazor.webassembly.js没有加载成功:

在此处输入图像描述

 dotnet new blazorwasm --hosted

The issue is relats that, by using the above command, it will create a multiple Blazor WebAssembly app, the solution contains three projects, like this:问题是,通过使用上述命令,它将创建一个多个 Blazor WebAssembly 应用程序,该解决方案包含三个项目,如下所示:

在此处输入图像描述

Then, if you use dotnet publish -c Release to publish the web apps, the published file will be located in the /bin/Release/{TARGET FRAMEWORK}/publish/wwwroot folder (In the Blazor.client and Blazor.Server projects). Then, if you use dotnet publish -c Release to publish the web apps, the published file will be located in the /bin/Release/{TARGET FRAMEWORK}/publish/wwwroot folder (In the Blazor.client and Blazor.Server projects) . Then, if you run the Blazor.Server.exe file, the Content root path is Server folder, and the blazor.webassembly.js file is in the Client folder, so it causes the blazor.webassembly.js file doesn't load successfully.那么,如果你运行Blazor.Server.exe文件,Content根路径是Server文件夹, blazor.webassembly.js文件在Client文件夹中,所以导致blazor.webassembly.js文件没有加载成功. Like this:像这样:

在此处输入图像描述

To solve this issue, you could try to assign an output directory when publish the web apps:要解决此问题,您可以尝试在发布 web 应用程序时分配 output 目录:

For example: In the E:\Temp\Blazor folder, I'm using the following command to create web apps, and publish the web app to the Publish folder.例如:在E:\Temp\Blazor文件夹中,我使用以下命令创建 web 应用程序,并将 web 应用程序发布到 Publish 文件夹。

dotnet new blazorwasm --hosted
dotnet publish -c Release -o E:\Temp\Blazor\Publish

After that, in the Publish folder, it contains all published files.之后,在 Publish 文件夹中,它包含所有已发布的文件。 Running the Blazor.Server.exe , the output as below:运行Blazor.Server.exe , output 如下:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 blazor wasm 托管项目中的 Serilog - Serilog in the blazor wasm hosted project 如何在 blazor 托管的 wasm 中使用 oauth2 - how to use oauth2 in blazor hosted wasm Blazor WASM(托管)重定向到手动输入的 URL - Blazor WASM (hosted) redirected on manually entered URL Blazor WASM AspNetCore 托管 JWT 授权问题 - Blazor WASM AspNetCore Hosted JWT Authorization issue 在 Inte.net Explorer 上运行 Blazor WASM 只是显示“Loading..”而不是有意义的错误消息 - Running Blazor WASM on Internet Explorer just shows "Loading.." instead of a meaningful error message 如何将自定义声明从 Duende IdentityServer 发送到 Blazor WASM 托管应用程序 - How to send custom claims from Duende IdentityServer to Blazor WASM Hosted app Blazor WASM Asp.net 核心是否托管 = Blazor 服务器端? - Is Blazor WASM Asp.net core Hosted = Blazor server side? Blazor WASM - 仅使选定的行可编辑 - Blazor WASM - Make only the selected row editable How to map fallback in ASP .NET Core Web API so that Blazor WASM app only intercepts requests that are not to the API - How to map fallback in ASP .NET Core Web API so that Blazor WASM app only intercepts requests that are not to the API Blazor WASM 应用程序中的 Object 参考未设置错误 - Object reference not set error in Blazor WASM app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM