[英]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.