本文介绍了发布应用程序后,blazor托管的模板项目无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从dotnet CLI创建了一个新的blazor托管项目,名为foo:

I create a new blazor hosted project, named foo, from the dotnet CLI:

dotnet new blazorwasm --hosted

我通过以下方式运行该应用程序

I run the app with

dotnet run -c Release

当请求https://localhost:5001(或5000)时,模板应用正确运行

The template app works correctly when requesting https://localhost:5001 (or 5000)

然后我通过以下方式发布该应用程序:

I then publish the app with:

dotnet publish -c Release

然后尝试使用

dotnet Server/bin/Release/net5.0/publish/foo.Server.dll

我希望该应用能够正确启动.但是我实际上得到了404响应.为什么会这样?

I expect the app to lanch correctly. But I actually get a 404 response. Why is that ?

注意:

  • 几天前它工作正常.
  • 发布时,我们收到消息优化程序集的大小,这可能会更改应用程序的行为.发布后一定要进行测试.请参阅: https://aka.ms/dotnet-illink".我认为这与我的问题无关,因为它之前一直可以正常工作.
  • 我使用的是Windows 10,dotnet sdk版本5.0.102
  • It was working properly few days ago.
  • When publishing, we get the message "Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink". I don't think this has anything to do with my issue as it was working properly before.
  • I'm on Windows 10, dotnet sdk version 5.0.102

推荐答案

Blazor WASM托管项目具有三个项目:客户端,服务器和共享项目.要将解决方案发布为一个发布站点,请运行命令

Blazor WASM Hosted project has three projects: client, server and shared.To publish the solution as a one publish site, run the command

dotnet publish MyWasmSolution.sln -C Release --output .\publish

发布文件夹包含服务器/客户端和共享的所有DLL,以及服务器和客户端的所有以及Windowsroot,包括blazor.webassembly.js及其所有压缩文件.

The publish folder contain all DLLs of server/client and shared and wwwroot of both server and client including blazor.webassembly.js with all compressed file.

然后,移至发布文件夹(内容根目录,因为 dotnet运行将当前文件夹视为内容根目录).

Then, move to the publish folder (the Content root, because dotnet run consider the current folder as the Content root).

运行下一个脚本:

cd path/to/folder/publish
dotnet foo.Server.dll

index.html已加载到浏览器中,如果您单击F12(开发工具),则不会发现错误.

The index.html is loaded in the browser and if you click F12 (dev tools) you find no errors.

这篇关于发布应用程序后,blazor托管的模板项目无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:14